2D Rotation with Quaternion gets stuck...
Hay there,
i'm making a small 2D Game with a friend of mine. We want to create a tower turning in the players direction. We found this solution, wich is working quite fine for a while but then gets stuck and the tower is not turning anymore.
Sorry for spelling mistakes, i'm not an english native.
void FixedUpdate()
{
if (player != null)
{
TowerRotation(player.transform);
}
}
void TowerRotation(Transform target)
{
Vector3 dir = target.position - shotSpawn[4].transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
Quaternion lerpTo = Quaternion.AngleAxis(angle, Vector3.forward);
shotSpawn[4].transform.rotation = Quaternion.Lerp(shotSpawn[4].transform.rotation, lerpTo, Time.time * rotSpeed);
}
Comment
Best Answer
Answer by seb34 · Jul 05, 2017 at 08:40 PM
We found the anwer. The Problem was Time.time. I'm still not sure why it behaved like it did but using a fixed number solved it.
Your answer
Follow this Question
Related Questions
2D AI movement 0 Answers
Selecting a game object in Unity 2d 3 Answers
NullreferenceException dealing damage to a child of the enemy 0 Answers
How can I reset the score counter? 2 Answers
how to disable dontdestroyonload on a specific scene 2 Answers