Sign in to follow this  

Best Ways to Shoot?

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

HI guys, got a ship model in my game and a load of aliens. what would you all suggest as the best way to get the thing shooting, would i need a class for the shot which draws a line as a method so that i could keep track of where the bullet is in order to do collision detection, any ideas will be greatly appreciated thanks all :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
hi,
first of all is your game 2d or 3d ? makes a differnce.

the way i learned it (and am still using) is to crate a bullet object(has to be derived bz a moveable object), which of this initialized with the position e gunbarrel (orgin), the speed the bullet will have(has to be faster than the ships own speed -> you´ll shoot yourselfd, and the lookAt vector (assuming your in FPS view) otherwise the attitude of the ship itself (or turret).

hope i that helps ... otherwise give us a more detailed description.

greetz from Austria
mauzi the Dude

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
this case only works if you animate the object every frame or similar, thats how you perfrom the colision detection( bounding box or poly intersection)
the bullet object has to hold a pointer to the shooter, so you´re able to trace back from who fire it and process the gamelogic accoringly.

but like i said, the more information you reveal, the easier it is for us to understand the problem.

greetz
the Dude

Share this post


Link to post
Share on other sites
Oh sorry, game uses 3d models but is played as a 2d game but in a 3d perspective i.e the ship can only move on the x axis and cannot move forward, backwards, up or down. the enemies move along the x axis and then move forward on the z much like space invaders so i dont think that the speed is an issue and will probably make it equal to the ship speed. game is much like space invaders but 3d models
thanks

Share this post


Link to post
Share on other sites
If you are limiting the bullets and ship direction so it can only go one way. It is reall easy. The way I implement bullets is with a class. I include a function for shooting drawing and animating(moving the bullets). Shooting I pass in the direction, position, and an identifier of who shot the bullet. Drawing should be obvious and animating should be obvious. In the class is an array of structs that includes vectors for position and direction and an int or char or pointer or whatever to identify the shooter as well as a bool for OnOff. I make it a static array with MAX_BULLETS so I don't process memory at runtime. Then when shooting, I test for the first bullet that is not on, set the structure at the pos and direction, turn it on. Then when drawing and animating, it loops through the array and draws and moves the one that are(IsOn==true). This may be a slow way, but it works really well for me. I don't know any easier way but I'm sure that there are different(read better) methods.

Share this post


Link to post
Share on other sites
As for collision detection here what you whant to do, assuming your bullet is of radius 1....

if (bulet.x > ship.x - ship.min.x && bulet.x < ship.x + ship.max.x)

then you wanna do that for each axis but like you said the Z Axis is not used so you can assume that all objects have a z of 0 and that all objects have a z size of 0

Share this post


Link to post
Share on other sites

This topic is 4719 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this