How can I rotate Seeker in place?


#1

I want to turn seeker in place when reached path.
I test this code. but It doesn’t work.

How can I?
I’m using rotation 2D.

void TurrningWhenReached()
{
    // AI is AIPath
    if (AI.reachedEndOfPath == false) return;

    Vector3 lookpos = transform.position;
    lookpos.x += dir.x;
    lookpos.y += dir.y;

    Quaternion rot = AI.SimulateRotationTowards(lookpos, AI.rotationSpeed * Time.deltaTime);
    AI.FinalizeMovement(transform.position, rot);
}

this function called in Update function.

I test with add some log in AIBase::FinalizeRotation function.
and I can check call 2 times (from my code first, and next AIBase::FixedUpdate).

How can I rotate Seeker in place?


#2

Hi

I think you will have to disable the agent’s internal movement code, otherwise that will override this. Try ai.canMove = false when it shouldn’t be moving by itself.


#3

I can check rotate in place

Thank you for your help. :smile:

and I can check my code wrong one more.

Vector3 lookpos = transform.position;
lookpos.x += dir.x;
lookpos.y += dir.y;

==>

Vector3 lookpos = dir;