# lookAt... mouse?

This topic is 2845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey

I'm working on a small bow and arrow game,
and I'm trying to make my bow "lookAt" my mouse. (make the bow rotate so it will point to the mouse coords on screen)

Any suggestions on how to do that?

##### Share on other sites
Some more details needed: 2D top view, 2D side view, 3D view, ..?

##### Share on other sites
i don't know what you mean...

##### Share on other sites

i don't know what you mean...

We need some details of how the game world is build and how the player sees the world. E.g. a 2D platform side-view like in Donkey Kong (on wikipedia) or an isometric view or a full 3D view, in the latter case either as first person or else as third person view. Perhaps you can provide a screen shot so far?

Then we need to know how the co-ordinates are given. Is the bow's co-ordinate frame given in world space or in screen space? The mouse position is obviously given in some kind of screen space until being transformed somehow. The spaces of bow and mouse have to be equalized before they can be used in the same computation. Also, do you deal with vector math or are you stick with trigonometry?

In a 2D sprite based game the bow will be represented by, well, a sprite Rotating the sprite may naturally happen around a corner of the sprite, while you need it e.g. around the center of the sprite.

And so on, and so on. You see, there are many details that have an influence on the solution. We need to know where to start, so I asked for some details on you game to not wildly guess what your needs are...

##### Share on other sites
oh okok no problem.. thanks for explaning

my game has a full 3d View, in third person mode ( so you see the bow from behind )
my bow's co-ordinates are given in world space (3D), then I translate it to 2D with the given perspective( to draw it on the screen ofc).

and yes, I deal with vector math, most of the calculations I do with vectors

here's an image for example:
http://imageshack.us...2/bowarrow.jpg/

I'm not using any graphic engine or any engine.. I write everything on my own

##### Share on other sites
Ahm...the theory is that you make a pick ray from your mouse. To do this multiply it with the inverse view&proj(correct me if I am wrong, never used it) matrix.
On the end you get a vector that shows in the direction your mouse points.
The bow only has to be aligned with the ray.

Hope that helps you!

##### Share on other sites
is there any other way I can solve this?

##### Share on other sites

is there any other way I can solve this?

Well, your mouse coords are 2D, your bow trajectory is 3D. So either you convert your 2d mouse coords into a 3d ray from camera to the projection surface, or convert an infinite amount of 3D points to 2D to see if they match the mouse coords. Your choice : )

##### Share on other sites
You might want to look at gluUnProject ( if you are using OpenGL ) , this converts 2D mouse coords into 3D world coordinates, which can be subtracted and used as a direction vector for your bow.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 9
• 11
• 15
• 21
• 26