- Home /
Question by
SkyBreaker · Sep 13, 2013 at 07:19 AM ·
c#rotationmovement scriptrotate object
How to rotate a GameObject around another object according to the mouse cursor position in C#
Hi Unity Heroes. I'm trying to rotate an object based on mouse cursor movement(like bubble gun in bubble shooter game). But I'm Filed to do that with my script.
MY script is :
mouse_pos = Input.mousePosition;
Debug.Log(mouse_pos);
object_pos = Camera.main.WorldToScreenPoint(target.position);
mouse_pos.x = mouse_pos.x - object_pos.x;
mouse_pos.y = mouse_pos.y - object_pos.y;
angle = Mathf.Atan2(mouse_pos.y, mouse_pos.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0, 0,-angle);
It rotates only its same position it won't move. Please any one help me to solve this. Or point me to any good tutorial ....
Comment
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Rotation around an axis, how unity handle this? 3 Answers
Rotating an object 3 Answers
FPS Controller rotate between two points c# 2 Answers
Player rotating towards direction of movement in 3D 1 Answer