Hey guys. Might seem a simple one but i do sometimes have trouble with these kind of rotation problems.
My end goal is to make sure all my NPCs are facing the right way when they move around the scene by always facing there current waypoint in a pathfinding script. As before they were gliding around with no relative rotation.
Ive tried ta few approaches none of which work how i need. Ill share them all to hopefully get some guidance on which one (if any) is the closest the actual approach i need.
Firstly i have a seperate child object which just contantly looks at the looks at current waypoint, and then i want to set my actual rotaion on the Y axis to match that rotation. However it seems i cant do this.
compass.LookAt(path.vectorPath[currentWaypoint]); // Child object always Looking in the direction of the current waypoint.
transform.rotation.y = compass.rotation.y; // Set my rotaion on Y to match that object on Y.
This gives an error…
Also this makes me face theat rotaion in ALL axis, when i only want the Y axis to change.
compass.LookAt(path.vectorPath[currentWaypoint]); // Child object always Looking in the direction of the current waypoint.
transform.rotation = Quaternion.Lerp(transform.rotation, compass.rotation, Time.deltaTime * turnSpeed); // Then set rotation to that compass look roation
And this one, while almost waht i ant makes them walk backwards everywhere. But it dies however only rotate the one Axis Y.
Vector3 faceThisWay = transform.position - (path.vectorPath[nextWaypointDistance]);
faceThisWay.y = 0.0f;
Quaternion newRotation = Quaternion.LookRotation(faceThisWay, transform.up);
transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 20);
So gang, which one is right and where is it going so wrong…
Many Thanks…