Sign in to follow this  
mcguile25

Moving while firing

Recommended Posts

mcguile25    235
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?

Share this post


Link to post
Share on other sites
Instruo    373
Not that it should make a huge difference, probably, but are you processing the moving or the shooting first in the frame?

Share this post


Link to post
Share on other sites
discman1028    212
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?

Share this post


Link to post
Share on other sites
iMalc    2466
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.

Share this post


Link to post
Share on other sites
giveblood    100
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.

Share this post


Link to post
Share on other sites
Drastick    132
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

Share this post


Link to post
Share on other sites
mcguile25    235
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.

Share this post


Link to post
Share on other sites
Ezbez    1164
I'm geussing that its what Drastick said. But that would be fairly minor difference for a fast-moving bullet.

Share this post


Link to post
Share on other sites
RanmaruX    122
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!

Share this post


Link to post
Share on other sites
discman1028    212
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!

Share this post


Link to post
Share on other sites
Palidine    1315
Quote:
Original post by iMalc
You mean it's bursting straight out of his chest?!?![lol]


That's actually how you do it so that aim "feels right" in an FPS. If you make the bullet come from the player's gun, and the gun is offset from the screen center then aiming doesn't work right. You fake that it's coming from the gun by having a particle effect shoot from the gun, then you LERP that effect into the position of the actual current position of the bullet that was shot from the player's chest. If you do the LERP right then player's wont notice that the bullet "curves" as it shoots across the screen.

-me

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Quote:
Original post by Palidine
Quote:
Original post by iMalc
You mean it's bursting straight out of his chest?!?![lol]


That's actually how you do it so that aim "feels right" in an FPS. If you make the bullet come from the player's gun, and the gun is offset from the screen center then aiming doesn't work right. You fake that it's coming from the gun by having a particle effect shoot from the gun, then you LERP that effect into the position of the actual current position of the bullet that was shot from the player's chest. If you do the LERP right then player's wont notice that the bullet "curves" as it shoots across the screen.

-me


I've always been annoyed by this practice in fps games...
most notably Halo2
Where someone can snipe by simply having an eye peek out from above an obstruction. Since the laser comes out his eye...(what is this? Superman laser vision?) Sure, thats a bad gameplay aspect... but on top of that... you'd see the character animation holding a gun pointed into the wall, with a wierd lerped laser flash going through it...

I've been considering having a 2 ray test solution...
project a ray from the players eye to find what target he is trying to hit. then for the actual projectile have the ray emit from the gun itself, but auto-aim at the player's sighted target
of course... alternatly you could have character's aim their guns like you would in real life... by lining up the gunsight with your eye...

Share this post


Link to post
Share on other sites

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