Sign in to follow this  

How can I simulate shooting?

This topic is 4729 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 Not sure if this should be in the beginners section but here goes anyway. I am continuing the development of my 3D Aeroplane game in Visual c++ 7 and DirectX 9. I am researching how I should handle shooting from my on screen aeroplane to an enemy plane. Both aeroplanes have their own simple bounding boxes around them. I have implemented some basic collision detection so that if the boxes touch a collision is registered. However, I now need to be able to shoot at the other aircraft and register any hits that they receive. I have a small gun sight on screen which will indicate where the bullets will go. I think that having a small bullet being seen to move across the screen would be pointless as it should move too fast to be seen. Also, I am not concerned about physics of bullets in this game. I just need find out how to get a straight line from my aeroplane to the enemy in my gun sights, to simulate that I have fired a shot and that the enemy bounding box has been hit. I have heard of ray casting but I have little information on it. Is this the direction I should be pursuing? If you need anything clarifying then just give me a shout. Thanks Dave

Share this post


Link to post
Share on other sites
Quote:
Original post by Red_Dash

I think that having a small bullet being seen to move across the screen would be pointless as it should move too fast to be seen


I think you should use moving bullets, because I'd think you would want your bullets to be tracers, to see where your shots are going.

Share this post


Link to post
Share on other sites
Just figure out how fast you want your bullets to move, how fast you want your guns to fire. So long as the player is holding down the shoot button, create a new bullet at the required interval; the bullet is just an object that has a velocity and position, and is displayed on screen as a little blur or a little bullet with a tracer behind it. They'd move super fast, and since you say you've already got collision code working, the rest is history.

Just remember to have the bullets 'die' when they get a certain distance away from the player, or you'll wind up with memory leaks because you'll have a billion bullets extending on into infinity.

Share this post


Link to post
Share on other sites
taking bullet's collision detection is not easy, i mean bullet is very fast thing and you should code a vector based coll. detection system for them(not position based) (i know lots of games whose walls are passable for player at high FPSs)
can't it be right that:
make a line from camera(or player) to map(which is the line that the bullet will go on)(do not have to scale the line), and when the player fires, just detect collisions on that line. bullet will go to closest collision area. this line will always be in front of the player and defines the bullets' path.

am i wrong? are there any games using this (or similar) technic?

Share this post


Link to post
Share on other sites
Ray casting/Ray tracing is the technique you need to accomplish this. A ray is basically a vector with an origin. The origin is the position of the gun and the vector is the direction the gun is facing. There are a number of ray/object intersection techniques you can implement. It happens to be easy to implement ray/object intersection with quadric surfaces because they are defined implicitly so you may want to use bounding spheres for hit detection. However, using bounding boxes is still acceptable. The position of the ray at any time t is origin + t * direction. Set this equation equal to the equation of your quadric and solve for t. If t is positive, then you intersected. If t is negative, then you intersected but the object is behind you. If t has no solutions or is complex, then you did not intersect.

One problem that always comes up with bounding volume intersection is misses being regarded as hits because the volume doesn't match the object exactly. if your model is low-poly, you could test for bounding volumes first, then if successful, test each polygon individually. If your models are high poly, you could consider using bounding boxes with an octree representation of the bounding boxes to cut down on the number of individual polygon intersection tests. All of these techniques require some bit of overhead, but they will give you a more accurate feel.

Hope this helps.

Share this post


Link to post
Share on other sites
Quote:
Original post by stroma
taking bullet's collision detection is not easy, i mean bullet is very fast thing and you should code a vector based coll. detection system for them(not position based) (i know lots of games whose walls are passable for player at high FPSs)
can't it be right that:
make a line from camera(or player) to map(which is the line that the bullet will go on)(do not have to scale the line), and when the player fires, just detect collisions on that line. bullet will go to closest collision area. this line will always be in front of the player and defines the bullets' path.

am i wrong? are there any games using this (or similar) technic?


why not have the bullet moving, and between its position and next position check whatever infront of it for a certain distance, so you dont miss any collisions

Share this post


Link to post
Share on other sites
Quote:
Original post by johnnyBravo
why not have the bullet moving, and between its position and next position check whatever infront of it for a certain distance, so you dont miss any collisions
and just said that but not make collision detection for all positions one by one, just make it when you fire and find where the bullet will go with the line. again bullet will go to position but it will not make any collision detection in air. isnt it a good technic for really "fast" bullets? (i see, for slow ones other one(that you mentioned) is better..)
i just want to know if it is usable., i mean i am not betting on it is the best. just an idea [wink]

Share this post


Link to post
Share on other sites
Hi Guys

Thanks for all the replies :-)

I have gone with a simple technique to start with. When the user presses a key to fire, a new bullet object is created and it is given a start position from the aircraft. Its trajectory is then calculated by using the lengths of the x, y and z axis to determine the size of steps the bullet will need to take to reach its destination (the center of the gun sight). It's destination x and y point is the center of the gun sight and the destination z point is just a #define MAX_DISTANCE that I have set that the bullet will go to, unless it meets anything, before it is destroyed.

So, what happens is that the bullet has its position incremented by the steps calculated earlier, on each frame. Once the bullet has moved, the bounding box of each enemy aircraft is checked to see if the bullet is inside it. If it is, then the collision routine is run, otherwise the bullet is moved and checked each frame until it reaches its maximum distance. Then it is destroyed.

I can see some disadvantages with this, including the fact that if the bullet moves fast (in large steps) then bounding boxes could be missed. At the moment this seems to work fine... but I have not tried it with lots of bullets firing at once yet or done any real testing to it. If I have problems then I will look into this ray casting method that has been mentioned.

Can anyone else see any flaws with the technique I have used, and are there any more suggestions?

Thanks again (I am sure there will be more questions soon!)
Dave

[Edited by - Red_Dash on December 31, 2004 7:03:19 AM]

Share this post


Link to post
Share on other sites
Divide the bullet steps into smaller steps, if they are larger than MAX_BULLET_STEP (which should be smaller than the smallest bounding box).
That way you are save at high fps, and you can forget about raytracing for now...

Share this post


Link to post
Share on other sites
If you're moving the player within the world - and not the world around the player - remember to adjust your velocity positioning accordingly.

What I mean is that the algorithm you've got - moving to the X, Y of the gunsight and going to MAX_DISTANCE on Z - is fine so long as your aircraft is oriented along the Z axis. The problem comes when the pilot banks left or right, or climbs up or down excessively. Then they become oriented along the X or Y axis instead of the Z axis.

This is one of the reasons why it's popular to rotate and move the world around the player and leave them stationary. just an afterthought.

An easier way would be to do a direct copy from the plane's vector, and give that to the bullet. Then just have it move in the direction of the vector at its velocity, thus eliminating the problem.

Share this post


Link to post
Share on other sites
Quote:
Original post by stroma
Quote:
Original post by johnnyBravo
why not have the bullet moving, and between its position and next position check whatever infront of it for a certain distance, so you dont miss any collisions
and just said that but not make collision detection for all positions one by one, just make it when you fire and find where the bullet will go with the line. again bullet will go to position but it will not make any collision detection in air. isnt it a good technic for really "fast" bullets? (i see, for slow ones other one(that you mentioned) is better..)
i just want to know if it is usable., i mean i am not betting on it is the best. just an idea [wink]


since per bullet movement, it is instant, you use a line intersection equation.
And then you can make the bullet movement really fast...

Share this post


Link to post
Share on other sites

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