- Home /
Rotation of an object with some delay..
I've just started working on unity with very little knowledge in scripting..as a learning activity i'm trying to rotate an object to the mouse pointer on click...so far i've got the rotation working but the rotation happens in a single frame and i want to make the object rotate with some delay...need help to figure that out. code so far is Ray ray = (Camera.main.ScreenPointToRay(Input.mousePosition)); Physics.Raycast(ray, out hit); hitpoint = hit.point; direction = hitpoint - this.transform.position; Vector3 relative = transform.InverseTransformDirection(direction); angleRad = Mathf.Atan2(relative.x,relative.z); angleDeg = angleRad * Mathf.Rad2Deg; transform.Rotate(Vector3.up,angleDeg);
I've used manual trigonometric calculations instead of functions like Quaternion.LookRotation just to get my hands dirty with vectors.
~Thanks
Your answer
Follow this Question
Related Questions
Camera rotation around player while following. 6 Answers
RayCasting shows wrong point 1 Answer
How would I slow down spinning toward the mouse? 1 Answer
Rotate an object accordingly to the angle from object to mouse position 2 Answers
Make my Gunpoint aim/rotate on the z axis towards my mouse cursor 1 Answer