- Home /
Angle to Rotation
I'm trying to make the gun follow and look at the mouse in 2D. So I calculate the angle between the mouse position and front direction of the gun.
What is then the proper way to then rotate the gun based upon the angle?
EDIT: so that little stick needs to be aligned with the red ray.
This is why I cant use lookAt. The gun flips:
Thanks.
Answer by sneftel · Jul 07, 2011 at 03:07 PM
There's really no reason to bring angles into this. You can transform the mouse position into world coordinates, then use Transform.LookAt()
to orient the gun towards it.
That "flips" the gun plane around each time you move the mouse from one side of the screen to the other.
Right.. lack of clarity is the problem here.. You need bigger and better pictures apparently.. describe this 'flip' you don't like. Give your gun a clear 'top' and 'bottom' and show us what it should look like in various situations.
Answer by NinjaSquirrel · Jul 07, 2011 at 08:02 PM
I solved this by using Quaternion.FromToRotation. I will delete this question is it is messy and I did not describe the problem like I should have.