#Smooth look at

1 messages · Page 1 of 1 (latest)

mellow zodiac
#

It wants to go in all 4 directions at the same time blobdoggoshruggoogly

minor lotus
#

with lerp

class Bacon_RotateTowardsLerpComponentClass: ScriptComponentClass {}

class Bacon_RotateTowardsLerpComponent: ScriptComponent 
{
    IEntity m_target;
    
    [Attribute("0.5", UIWidgets.Auto, "Lerp pct")]
    float m_lerpPct;
    
    override void OnPostInit(IEntity owner)
        SetEventMask(owner, EntityEvent.INIT);

    override void EOnInit(IEntity owner)
    {
        if (SCR_Global.IsEditMode())
            return;

        SetEventMask(owner, EntityEvent.FRAME);
        owner.SetFlags(EntityFlags.ACTIVE, false);
    };
    
    override void EOnFrame(IEntity owner, float timeSlice)
    {
        m_target = SCR_PlayerController.GetLocalControlledEntity();
        if (!m_target)
            return;
        
        vector myMatrix[4];
        owner.GetWorldTransform(myMatrix);

        vector lookAtMatrix[4];
        SCR_Math3D.LookAt(owner.GetOrigin(), m_target.GetOrigin(), vector.Up, lookAtMatrix);

        vector finalMatrix[4];
        SCR_Global.LerpMatrix(myMatrix, lookAtMatrix, finalMatrix, m_lerpPct * timeSlice);
        
        finalMatrix[3] = myMatrix[3]; // probably not necessary?
        owner.SetWorldTransform(finalMatrix);
    };
};
#

but this is only across one axis

mellow zodiac
#

Why is LerpMatrix in SCR_Global and not Math notlikemeow

#

finalMatrix[3] = myMatrix[3]; This is needed

#

But it works on all axis

minor lotus
#

this works on all axis yes

class Bacon_RotateTowardsLerpComponentClass: ScriptComponentClass {}

class Bacon_RotateTowardsLerpComponent: ScriptComponent 
{
    IEntity m_target;
    
    [Attribute("0.5", UIWidgets.Auto, "Lerp pct")]
    float m_lerpPct;
    
    override void OnPostInit(IEntity owner)
        SetEventMask(owner, EntityEvent.INIT);

    override void EOnInit(IEntity owner)
    {
        if (SCR_Global.IsEditMode())
            return;

        SetEventMask(owner, EntityEvent.FRAME);
        owner.SetFlags(EntityFlags.ACTIVE, false);
    };
    
    override void EOnFrame(IEntity owner, float timeSlice)
    {
        m_target = SCR_PlayerController.GetLocalControlledEntity();
        if (!m_target)
            return;
        
        vector directionMatrix[4];
        vector desiredDirection = vector.Direction(owner.GetOrigin(), m_target.GetOrigin()).VectorToAngles();
        Math3D.AnglesToMatrix(desiredDirection, directionMatrix);
        
        vector myMatrix[4];
        owner.GetWorldTransform(myMatrix);
        
        vector finalMatrix[4];
        SCR_Global.LerpMatrix(myMatrix, directionMatrix, finalMatrix, m_lerpPct * timeSlice);
        
        finalMatrix[3] = myMatrix[3];
        owner.SetWorldTransform(finalMatrix);
        
    };
};
#

lookat will only do it across one I guess?

mellow zodiac
#

Your first code worked already

minor lotus
#

oh ok I didn't realize because my origin was at my feet I guess, so now you have 2 ways to do same thing kekw

mellow zodiac
#

I didnt know the GetWorldTransform. But thats way easier

#

Thanks alot blobcloseenjoy

mellow zodiac
#

To look at player eye pos:

ChimeraCharacter targetPlayer = ChimeraCharacter.Cast(m_Target);
SCR_Math3D.LookAt(GetOwner().GetOrigin(), targetPlayer.EyePosition(), vector.Up, lookAtMatrix);
minor lotus
#

nice, though the camera is actually somewhere around the nose I think