- Home /
Look rotation makes sudden changes
This is a racing game, I use http://arongranberg.com/astar/ pathfinder for the character runs on a oval racetrack. Player can only play with the characters speed which is calculated and has a high limit. When the player reaches high range of speed character suddenly looks left or right for a moment and straightens back and its very annoying. Its not happening with low speed. What am i missing? The dir vector is calculated same with the astar tutorials. I also use simple smooth modifier.
dir = (path.vectorPath [currentWaypoint] - transform.position).normalized;
Vector3 rot = dir;
rot.y = 0f;
var targetRotation = Quaternion.LookRotation (rot, Vector3.up);
transform.rotation = Quaternion.Slerp (transform.rotation, targetRotation, Time.deltaTime * speed * 0.3f);
characterController.SimpleMove (dir * speed * 0.8f);
Does it only happen near a waypoint (if you have a long, straight section, then a curve, will it only do it when you get to the end)?
Suppose you pass a target to the side. The code makes if always try to look at the target, turning faster as you go faster. So now it's looking sideways to see it, until it turns to see the next one.
I also tested with long straight section and then a curve; it starts happening from the begining. I also put the target in front of the character and it happens :( I fixed the turning speed and nothing changes.
Answer by vantilator · Jun 01, 2015 at 01:16 PM
I found a solution:
When i checked the angles between dir and transform.position the values are like:
143.7691 143.8332 . . 145.8065 . . 52.40902 (eww!) . . 140.2589
I dont know why my direction vector changes suddenly. Now im checking for sudden angle change and it seems ok, probably not the best solution.