Jump to content
  • Advertisement
Sign in to follow this  
ido098

lookAt... mouse?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey :o

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 smile.png

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!