x


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.

alt text

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:

alt text

alt text

Thanks.

more ▼

asked Jul 07 '11 at 12:19 PM

NinjaSquirrel gravatar image

NinjaSquirrel
759 31 41 69

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Jul 07 '11 at 03:07 PM

sneftel gravatar image

sneftel
1.7k 7 9 20

That "flips" the gun plane around each time you move the mouse from one side of the screen to the other.

Jul 07 '11 at 07:22 PM NinjaSquirrel

You want the gun to go upside down?

Jul 07 '11 at 07:25 PM flaviusxvii

I'm not sure what you mean.

Jul 07 '11 at 07:34 PM NinjaSquirrel

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.

Jul 07 '11 at 07:38 PM flaviusxvii

Added clarification. ^

Jul 07 '11 at 07:53 PM NinjaSquirrel
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jul 07 '11 at 08:02 PM

NinjaSquirrel gravatar image

NinjaSquirrel
759 31 41 69

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2245
x1071
x300

asked: Jul 07 '11 at 12:19 PM

Seen: 1264 times

Last Updated: Jul 07 '11 at 08:02 PM