- Home /
Question by
jacen · Feb 05, 2015 at 10:32 PM ·
c#movementacceleration
Trouble with diagonal acceleration in Quake style movement
I'm trying to implement Quake 3 style movement in Unity and I've ran into a little problem with diagonal movement. It works fine if you press the two movement keys at the same time. My problem is if you press one key, wait for it to get up to speed, and then press the second, it only changes direction a little bit.
Here's my acceleration code.
void Accelerate(float accel, Vector2 want_dir)
{
Vector3 vel = new Vector3(velocity.x, velocity.z);
double current_speed = Vector3.Dot(vel, want_dir.normalized);
if (current_speed < max_move_speed)
{
velocity += new Vector3(want_dir.x, 0, want_dir.y) * accel * Time.deltaTime;
}
}
The value of want_dir corresponds to key presses. X is equal to 1 if the right strafe key is pressed, -1 if left is pressed, 0 if neither. Y is the same, but for forward/backward.
If it's any help, this article is where I got my info on how Quake's acceleration works, as well as that little snippet.
Comment