- Home /
2D arm rotation using mouse
Hello, I'm trying to rotate the arm (plane) object in z axis using the x and y positions of the mouse. I did the same thing in c++ language a while a go, but I feel like there is an easier way in unity.
I tried this code in my arm object, but it rotates it in x and y axis. opposite of what I want.
var position = Input.mousePosition;
newposition = Vector3(position.x,position.y,-camera.main.transform.position.z);
var lastposition = camera.main.ScreenToWorldPoint(newposition);
transform.LookAt(lastposition);
Has anyone did something similar?
Thanks
Comment
Your answer
Follow this Question
Related Questions
LookAt() not working with mouse as target in 2D 1 Answer
Rotate plane on a pivot to the mouse position (in 2D) 1 Answer
I need help with clamping a rotation towards the mouse position 2 Answers
object rotates toward mouse? 2D Top Gameplay 6 Answers
Why Rotate player toward mouse direction keeps increasing rotation speed? 1 Answer