Confused about lookAt

I’m getting confused about how lookAt works, I would assume it attempts to match up the local forward vector in world space with the local forward vector in world space of my second object.

But taking a look in my scene the local coordinate system of every tile matches world space axis, attempting to do my own smoother rotation with:

            while (time < 1f)
            {
                transform.position = Vector3.Lerp(startPos, endPos, time);
                transform.forward = Vector3.Slerp(fwdVec, waypoint.transform.forward, time);
                time += Time.deltaTime * _speed;

                yield return new WaitForEndOfFrame();
            }

Didn’t give me the desired result and didn’t rotate my object at all, which is obvious when all local coordinate systems of every object match up with world space.

No. LookAt points the object towards the passed in position. That is, it rotates it so that the forward vector points at the target

If you want to do it smoothly, you can calculate the vector from this object to the target

Vector3 targetDirection = (target.transform.position - transform.position).normalized;

Then Slerp from start forward to target direction

Vector3 startForward = transform.forward;
transform.forward = Vector3.Slerp(startForward, targetDirection, time);
1 Like

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

Privacy & Terms