Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Trajectory of a bullet

Author
Message
Veron
17
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 6th May 2009 09:18 Edited at: 6th May 2009 09:18
Hey guys,

I'm working on rewriting certain parts of my FPS engine, and i've stumbled across a few problems in writing up some decent code for shooting. Ever since I modified the mouselook/player movement, the shooting has been acting strange.

When I click to fire, the bullet is positioned at the camera (player) position, then pointed straight ahead using the set object to camera orientation command. Then, I set a flag to one, and if that flag is equal to 1, i'll move the bullet using the MOVE OBJECT command. When the bullet is a certain distance away, the flag is set to 0 and hidden. The problem is that the X, Y, and Z position of the bullet is constantly decreasing as soon as the bullet is fired, rather than just moving in a perfectly straight line, straight ahead from where i'm looking.

My movement code:


My mouselook code:


My shooting code:


Any help with getting the bullet to just move in a straight line in front of me rather than moving on all 3 axes would be great. Thanks.

ulogix
15
Years of Service
User Offline
Joined: 1st May 2009
Location:
Posted: 6th May 2009 13:29 Edited at: 6th May 2009 14:59
I'll explain conceptually...

You don't normally need to create physical objects for bullets because in real life they move so fast you can't see them. For bullets, the best way is to use "line of site" methods of collision testing to see if your "invisible" line hits the target.

For slow missiles such as rocks being thrown, arrows or cannon ball being fired etc, it's a different story. Then you do need trajectory calulations. For simplicity you can ignore wind drag, in which case the horizontal component of the velocity is always constant. The only difficult part is therefore the vertical velocity which decreases as the object is thrown upwards, then increases on it's way back down.

Going back to the bullet, to add a touch more realism, you could be really clever and use trajctory equations to calculate the effective range of the weapon. But that's unnecessarily complex. A far simpler way is just to decide on an effective range, then test for this distance to the target object.

Do a search because there are various code examples of how to do this.
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 6th May 2009 16:47
Though it does not appear as such, the camera is likely pointing downward slightly. Have your code print the camera angles to the screen to verify this.

LBFN
Veron
17
Years of Service
User Offline
Joined: 22nd Nov 2006
Location:
Posted: 7th May 2009 09:48
Quote: "Though it does not appear as such, the camera is likely pointing downward slightly. Have your code print the camera angles to the screen to verify this."


The thing is, even if it is pointing down, it will move down *extremely fast*, even if the camera is tilted down the slightest bit, so it'll move down as fast as it moved ahead. Obviously, a way to counter this would be to lower the MOVE OBJECT speed of the bullet, but then i'll be waiting forever for it to move!

When it comes to not having an object at all, i'd have no idea how to do it when it comes to code, apart from using the INTERSECT OBJECT command, and using a limb extended from the player, but i've tried that and it didn't work. Also, for things like automatic weapons, that sort of thing could prove tough, so I think actually creating the bullet as an object would be my best bet. Searches have revealed nothing when it comes to the shooting code, so I assume my shooting code is correct, which is why I suspected my camera and mouselook code to be the problem.

LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 7th May 2009 17:30
Make a final adjustment to the angle of the bullet as it is fired so that it does not go downward (or at a lesser angle, perhaps).

From the code you posted, I don't see how the bullet ever gets fired in the first place, as clicking the left mouse button sets bulletfiredaway to 0 (seems like it should be 1). I don't see where you obtained cammovex# and cammovey# from, so I could not duplicate what it is that you are doing there.

I would suggest that you count the number of times the bullet is actually moved instead of the bullet's x position (10,000 seems like a long ways for a bullet to travel).

Hope this helps,

LB

Login to post a reply

Server time is: 2024-09-28 06:23:55
Your offset time is: 2024-09-28 06:23:55