Quantcast
Viewing all articles
Browse latest Browse all 133

How to rotate smoothly

Hey, I started Unity a week ago and until now some search here help me but now I'm kinda stuck. The thing is, I want to rotate an arm smoothly with the mouse Y coordinate so I try to use Quaternion.Slerp and all but the arm still teleport from one position to another if, for example, I let go the mouse button and I click on another Y position. Here is my code: void Start () { ArmStart = transform.rotation; } void Update(){ Vector3 mousePos = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 10); Vector3 lookPos = Camera.main.ScreenToWorldPoint (mousePos); Vector3 BoundPos = Camera.main.ScreenToViewportPoint (mousePos)*100; if (Input.GetMouseButton(0)&& BoundPos.x < 96 && BoundPos.x > 65 && BoundPos.y < 90 && BoundPos.y > 55) { float speed=50f; float angle = ((Mathf.Atan2 (lookPos.z, -lookPos.y) * Mathf.Rad2Deg) - 130) * 2.8f; Quaternion ArmGoal = Quaternion.AngleAxis (angle, Vector3.forward); transform.rotation= Quaternion.Slerp(ArmStart,ArmGoal,speed*Time.deltaTime); ArmGoal=ArmStart; } } Don't mind the condition for the if, it's cause I want that we can control the arm inside precise bound. If you have any idea why it don't work or if you have a better idea... or if you just want to laugh at a damn noob answer please.

Viewing all articles
Browse latest Browse all 133

Trending Articles