0
\$\begingroup\$
void FixedUpdate()
    {
        LiftProcess();
        MoveProcess();
        TiltProcess();

        if (hasRotate == true)
        {
            Vector3 targetDirection = helicopterPlatform.transform.position - transform.position;
            Vector3 newDirection = Vector3.RotateTowards(transform.forward, targetDirection, lookAtSpeed * Time.deltaTime, 0.0f);
            transform.rotation = Quaternion.LookRotation(newDirection);
        }
    }

I want ot make a check IF transform.rotation has finished and the transform is facing the newDirection then change the flag hasRotate to false. What check and how should I apply ?

\$\endgroup\$
1
\$\begingroup\$

You can check if ( Vector3.Angle(newDirection, targetDirection) < thresholdDegrees), where you can set the threshold in degrees as tight as you like.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I'm getting errors since newDirection and targetDirection are Vector3 and not Quaternion and if I tried to put there the rotations it's never get to set the flag to false : if (Quaternion.Angle(transform.rotation, helicopterPlatform.transform.rotation) <= thresholdDegrees) { hasRotate = false; } \$\endgroup\$ – Benzi Avrumi Jul 30 at 19:00
  • 1
    \$\begingroup\$ Ah, whoops, I misread. Just use the vector version instead of the quaternion version. Edited to show this. \$\endgroup\$ – DMGregory Jul 30 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.