- Home /
how to rotate a rigidbody to a point on a plane on mouse down
Hi im new to a unity im trying to build a rts game and i want to be able to rotate my ship as a rigid body so that when i mouse down in game it rotates towards the location which i have clicked i have searched the forums for days yet to find a answer to help hopefully some one can give me a solution.
Answer by SarperS · Jun 22, 2016 at 05:25 AM
Put your plane in a specific layer. On mouse down, send a raycast with a layermask that only contains your plane's layer. Then compute a look rotation using that raycast 's hit position.
Here is how you compute a look rotation https://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html
If you don't want to cast a ray and use layers another thing you can do is, you can convert the mouse position into the world space, and use that in look rotation computation. As you are working on a top-down game with 2D movement space, that should suffice.
Your answer
Follow this Question
Related Questions
Lookat Direction by AddTorque? 0 Answers
Rotating a MeshCollider 0 Answers
Have an object bounce off colliders instead of drift 2 Answers
How to make a RigidBody not go into ground when tilted foward? 2 Answers
Rigidbody goes wonky after collision 0 Answers