Weird rotation

Hi, there

Its very simple problem, but Im so tired looking ahead… maybe someone can help me out

This code should rotate my object to look on next waypoint while moving, but… it looks only when going to next+1 waypoint

for example If I want to go back ONE waypoint, then my controller goes backwards, but when it will be 2 waypoints away, then controller turns around…

and I cant get it :frowning:

if (smoothRotation){
         
var rotation = Quaternion.LookRotation(waypoints[targetwaypoint].position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationDamping);

}

I’ve got a very similar problem, and so far the only thing I can work out to what is going on, is that Quaternion.LookRotation is behaving as if the gameObject its being called on is always at 0,0,0, so the moment you leave 0,0,0 (which is where I presume your object is starting from?) the next call to Quaternion.LookRotation isn’t going to be what you expect, but I still can’t think my way around this, I’m sure there is a way but I’ve not read it anywhere yet nor thought of it myself :frowning:

Edit:
nvm me, dunno why i totally ignored the whole target.position - transform.position stuff, just me thinking this would behave more like LootAt.

MdK

One thing which would be simple… just an idea…
waypoints[ ] is numbered starting from 0 (zero) so the first waypoint is waypoint[0] and the second is waypoint[1] so if your targetwaypoint is counting from 1 then you need to subtract one… so Quaternion.LookRotation(waypoints[targetwaypoint**-1**].position

I have no idea, but I like to explore simple answers first.

Good luck.

thank you :slight_smile: