- Home /
Why Is This Happening: Slerp Rotation Issue
Hello,
I have a trigger collider in my scene, when the player walks through it, it rotates the player 90/-90 degrees on the Y axis. Only problem is, is that it doesn't do that - it jitters at around 45 degrees (as if its stuck between 90 and -90).
var controller : GameObject;
var direction : String = 'left';
private var inTurn : boolean = false;
private var NewTurn = Quaternion.Euler (0, 0, 0);
function Update () {
controller.transform.localRotation = Quaternion.Slerp(controller.transform.localRotation, NewTurn, Time.deltaTime * 6);
}
function OnTriggerEnter (object : Collider) {
if(object.transform.name == 'Player'){
if(direction == "left"){
NewTurn = Quaternion.Euler (0, -90, 0);
}
else if(direction == "right"){
NewTurn = Quaternion.Euler (0, 90, 0);
}
}
}
Now, this works fine if I only have ONE trigger game object within the scene. But if I have more, then it jitters - which is weird because the other triggers are not even being triggered, they're on the other side of the map.
All I want to do, is animate the player rotating -90 / 90 degrees on the Y axis when it walks into the trigger object.
more than one thing affecting the rotation would be my guess... Something else sets it and then this code is fighting to change it but keeps finding it changed back again.
Right, I've deleted every trigger object, except one - and it works fine. As soon as I duplicate a new one, and move it out of range, it starts jittering, as if its trying to counteract?? So confused, that trigger isnt even being triggered!
I'm too tired - It's clearly the Update Function counteracting!
How would I get it so it just smoothly rotates the player to a given angle?
Your answer
Follow this Question
Related Questions
Rotate slowly to target position? 3 Answers
Rotating a character smoothly 0 Answers
Quaternion.Slerp problem... 1 Answer
Quaternion.Slerp only one axis? 1 Answer
Jitter on Slerp - Raycast 0 Answers