Archived

This topic is now archived and is closed to further replies.

How to implement bullets in 3D world

This topic is 5778 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

I have a game (3rd person view) where I move my mouse cursor as a crosshair to target enemies, the problem is how to implement : 1. my bullets direction in 3D world given the position of the mouse on the screen. 2. the best way to do collison detection of my bullets. I need to implement some sort of level of accuracy of my shooting process. Can somebody give me a good idea or article where I can read ??

Share this post


Link to post
Share on other sites
I''m not a 3D programmer, but I think that if you assume that the mouse cursor is positioned at location (mouse_x,mouse_y, Z) where Z is a constant > 0,
and the position is reletive to the player,
you can calculate the vector of movement from the position of the player to the mouse location.

cheers.

(: I am what I am, more or less

Share this post


Link to post
Share on other sites
1. Your coordinate system is composed of 3 vectors - right, up, and look. All you have to do is figure out how to calculate the look vector. The look vector points along where you are looking.

There are two ways to find the look vector. If you are keeping track of your rotation angles (pitch, yaw, roll), you can calculate it easily using some trignometry. The second way is to extract it right from the modelview matrix. In openGL, its something like this (I didn''t try this code to see if it works):

  
GLfloat MV[16];
glGetFloatv(GL_MODELVIEW_MATRIX, MV);
CVector look(MV[2], MV[6], MV[10]); // i think this is right




2. The type of collision detecting you implement depends on what type of collision detection system you are using right now. The quickest way to implement collision detection is use OpenGL''s support for picking. Check NeHe''s tutorials for an expample of this.

For my landscape engine I use raycasting through my quadtree to determine collisions.

Does anyone have experience with raycasting through BSPs? I am curious how computationally expensive raycasting through a BSP is, compared to an octree/quadtree.

Share this post


Link to post
Share on other sites