- Home /
How would I slow down spinning toward the mouse?
Right now I have it where my character immediately follows the mouse and I wanted to know if you could put a delay on it somehow and make it slow down. It is also a 2D object. If you know how to do this, I would greatly appreciate it if you could help. Thanks!
if (Time.timeScale == 1) {
Vector3 mousePos = Input.mousePosition;
mousePos.z = 0f;
Vector3 objectPos = Camera.main.WorldToScreenPoint (transform.position);
mousePos.x = mousePos.x - objectPos.x;
mousePos.y = mousePos.y - objectPos.y;
float angle = Mathf.Atan2 (mousePos.y, mousePos.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler (new Vector3 (0, 0, angle));
}
Comment
Best Answer
Answer by robertbu · Nov 08, 2014 at 05:38 AM
Replace line 10 by:
Quaternion qTo = Quaternion.Euler (new Vector3 (0, 0, angle));
transform.rotation = Quaternion.RotateTowards(transform.rotation, qTo, speed * Time.deltaTime);
Where 'speed' is a variable you define and assign the degrees per second you want to allow.
Your answer
Follow this Question
Related Questions
Create objects on a mouse click in 2D 1 Answer
Mouse event build up? 0 Answers
Make player face same direction as camera. 4 Answers
How does the event delat and event current work? 1 Answer
get nearest game object 1 Answer