Difference between .forward = vec3 and .rotation = Quaternion.rotation(vec3)?

Just looking at the FacePlayer/FaceTarget methods again and realised I had

        protected void FaceTarget()
        {
            if (StateMachine.Targeter.CurrentTarget == null) { return; }

            Vector3 facing = StateMachine.Targeter.CurrentTarget.transform.position - StateMachine.transform.position;
            facing.y = 0f;

           // ----------------------- The below line changes ---------------------
            StateMachine.transform.forward = facing;
        }

 

rather than

        protected void FaceTarget()
        {
            if (StateMachine.Targeter.CurrentTarget == null) { return; }

            Vector3 facing = StateMachine.Targeter.CurrentTarget.transform.position - StateMachine.transform.position;
            facing.y = 0f;
           // ----------------------- The below line changes ---------------------
            StateMachine.transform.rotation = Quaternion.LookRotation(facing);
        }

I’m not as up to snuff on Quaternions and how Unity actually handles rotations as i could be or enough to figure out if there is actually a difference in the result. From what I can figure out they should be the same. If that is the case is one is either more performant or more standard?

Both methods are equally valid, just using a different way of visualizing the same thing. Either method is acceptable.

Performance is identical, because changing transform.forward causes the Transform to call Quaternion.LookRotation to set the rotation.

Thanks, I really need to get used to looking at the declarations - that would have solved my question.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms