Moving while firing

Started by
11 comments, last by GameDev.net 18 years, 1 month ago
Hi guys, just had a quick question that I hope has a quick answer :) In my 3D game, I am having a problem with firing bullets and having them render in the appropriate spot _while_ I am actively moving side-to-side or diagonlly or whatnot. The bullets seem to "lag" behind, so for instance, if I am strafing horizontally to the right, the bullets appear to the left at the previous position I was. Now, if I am just standing still, I can look up/down, rotate the camera, and shoot, and the projectile is fired in the correct spot. I think I've tried just about everything imaginable to try and get this to work. Why would it not show up in the correct spot while running side to side or diagonlly or whatever? In my player's HandleInput function, first I have the code to handle player position updates, then if the player fires, a projectile is started from the player's position and direction x/y angles. So the projectile is getting the starting position from the player, so it should be up-to-date by the time the player is moving and shooting. Any suggestions? Do you need code samples?
Advertisement
Not that it should make a huge difference, probably, but are you processing the moving or the shooting first in the frame?
"Game Programming" in an of itself does not exist. We learn to program and then use that knowledge to make games.
If this is a human model, maybe the bullet should start from the inside of the gun and not the center of the human? (Or better, the end of the barrel of the gun.)

Does it appear to the left of the player and not move at all?
--== discman1028 ==--
Quote:Original post by mcguile25
a projectile is started from the player's position and direction x/y angles.
You mean it's bursting straight out of his chest?!?![lol]

Well then, by the time you can see the bullet in front of you, you will have moved sideways a bit wont you? Try ofsetting the bullet forwards a little so that it actually starts in front of the player. At the tip of the gun to be more precise, which I presume is in the middle of the screen (Doom1 style), in this case?
I think you'll find that this solves the problem.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
this seems pretty obvious to me so i don't know if you have already tried this, but - worst case scenerio, set it so that the bullet, instead of starting where you are tryign to have it start, starts at where you are going to be after you moved.
-Chris
You should use the inherit velocity from the player. If you throw a rock from a moving car then the rock is already moving at the speed and direction of the car. If you throw it then it starts with that velocity then external forces may act on it (Wind, drag, gravity, so on...) You may have the same problem if you were moving forward and shot a slow rocket it is possible that it would lag behind you then tag you right in the back of your head.

BulletVel = PlayerVel + EjectionVel
Ah, thanks for the replys guys. I think I (partly) figured out what's going on. It seems to be a timing issue. The gun and the player have a "Time Last Updated" variable (as do all objects in the game..). What was happening was that once the projectile was fired, the time last updated variable was set to the current time for the projectile (consequence of calling object->SetActive()), but for the player, the time last updated could be anything. So when activating the projectile, I set the time last updated variable for my projectile to be the same as the player's time last updated.

Now, it's working a lot better, but it's still off a bit when strafing and such, but it's damn close..I'll have to keep working at this to figure out what's going on.
I'm geussing that its what Drastick said. But that would be fairly minor difference for a fast-moving bullet.
I think Drastick is right too although this seems to be ignored in most FPS games cause it can make it a bit difficult to aim. Basically it's a result of the player being able to move faster than his bullets do.

This is why in Quake 3 you can launch yourself on a jump ramp and then fire rockets that hit the ground after you do!
Quote:Original post by RanmaruX
This is why in Quake 3 you can launch yourself on a jump ramp and then fire rockets that hit the ground after you do!


My favorite method of suicide!
--== discman1028 ==--

This topic is closed to new replies.

Advertisement