Archived

This topic is now archived and is closed to further replies.

Gammastrahler

Horizontal Velocity for First Person Shooter

Recommended Posts

Gammastrahler    150
hi, i have tried to incorporate a horizontal velocity in my movement code, where i use only one value for both x and z: the problem is that the acceleration and decceleration is not working constant, sometimes it is faster, then slower, or even there is no velocity at all or i must turn around the axis so it will work again.... the source code is as follows:
  
if (move)   // player is moving or strafing

    velocity += 0.002 * 32;
else
    velocity -= 0.002 * 32;

if (velocity > 1.0) velocity = 1.0;
if (velocity < 0.0) velocity = 0.0;

// x delta and z_delta are already computed according to

// y and x axis of mouse look


// finally the velocity is applied:


x_delta *= velocity;  
z_delta *= velocity;

// set camera


camera[0] += x_delta;
camera[2] += z_delta;

  

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Hmm. What FPS are you running? If you call this once a frame, you''ll be at full velocity in 16 frames. If you''re running at, say, 75 fps, that''s zero to full speed in 2 tenths of a second. Shouldn''t you be multiplying by a time delta somwhere in there?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
quote:
Original post by Gammastrahler
thankx, but x_delta and z_delta are multiplied by the time delta between each frame, this should be right i think?



Nope. You''re correcting your velocity for time, but not your acceleration. You need to use the time delta in your velocity += and -= lines.

Share this post


Link to post
Share on other sites