Q2 air acceleration, jump fix
This commit is contained in:
@@ -581,6 +581,8 @@ namespace Game
|
|||||||
|
|
||||||
[ReadOnly] public bool onGround = false;
|
[ReadOnly] public bool onGround = false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
// QW
|
||||||
private const float friction = 4f;
|
private const float friction = 4f;
|
||||||
private const float stopspeed = 100f;
|
private const float stopspeed = 100f;
|
||||||
private const float accelerationGround = 10f;
|
private const float accelerationGround = 10f;
|
||||||
@@ -588,13 +590,31 @@ namespace Game
|
|||||||
|
|
||||||
private const float maxAirSpeed = 320f;
|
private const float maxAirSpeed = 320f;
|
||||||
private const float maxAirStrafeSpeed = 30f; //Q2+
|
private const float maxAirStrafeSpeed = 30f; //Q2+
|
||||||
private const float airAcceleration = 0.4f * 0f; //Q2+
|
private const float airAcceleration = 0f; //Q2+
|
||||||
private const float airStopAcceleration = 2.5f * 0f; //Q2+
|
private const float airStopAcceleration = 0f; //Q2+
|
||||||
private const float airStrafeAcceleration = 70f * 0f; //CPM?
|
private const float airStrafeAcceleration = 0f; //CPM?
|
||||||
private const float strafeAcceleration = 10f; //QW
|
private const float strafeAcceleration = 10f; //QW
|
||||||
private const float airControl = 0f; //CPM
|
private const float airControl = 0f; //CPM
|
||||||
private const float stepSize = 16f;
|
private const float stepSize = 16f;
|
||||||
private const float autoJumpTime = 0.4f;
|
private const float autoJumpTime = 0.4f;
|
||||||
|
*/
|
||||||
|
|
||||||
|
// GOA
|
||||||
|
private const float friction = 6f;
|
||||||
|
private const float stopspeed = 100f;
|
||||||
|
private const float accelerationGround = 12f;
|
||||||
|
private const float jumpVelocity = 270f;
|
||||||
|
|
||||||
|
private const float maxAirSpeed = 320f;
|
||||||
|
private const float maxAirStrafeSpeed = 30f;
|
||||||
|
private const float airAcceleration = 0.4f;
|
||||||
|
private const float airStopAcceleration = 2.5f;
|
||||||
|
private const float airStrafeAcceleration = 0f;
|
||||||
|
private const float strafeAcceleration = 10f;
|
||||||
|
private const float airControl = 0f;
|
||||||
|
private const float stepSize = 16f;
|
||||||
|
private const float autoJumpTime = 0.4f;
|
||||||
|
|
||||||
//private bool physicsInteractions = false;
|
//private bool physicsInteractions = false;
|
||||||
|
|
||||||
private bool jumped = false;
|
private bool jumped = false;
|
||||||
@@ -678,7 +698,6 @@ namespace Game
|
|||||||
|
|
||||||
// TODO: snap to ground here
|
// TODO: snap to ground here
|
||||||
|
|
||||||
|
|
||||||
bool jumpAction = InputManager.GetAction("Jump");
|
bool jumpAction = InputManager.GetAction("Jump");
|
||||||
|
|
||||||
if (jumped && !jumpAction)
|
if (jumped && !jumpAction)
|
||||||
@@ -686,12 +705,9 @@ namespace Game
|
|||||||
else if (jumped && Time.GameTime - lastJumped >= autoJumpTime)
|
else if (jumped && Time.GameTime - lastJumped >= autoJumpTime)
|
||||||
jumped = false; // jump timeout
|
jumped = false; // jump timeout
|
||||||
|
|
||||||
if (onGround)
|
|
||||||
{
|
|
||||||
// jump
|
// jump
|
||||||
if (jumpAction && !jumped)
|
if (onGround && jumpAction && !jumped)
|
||||||
{
|
{
|
||||||
Console.Print("jumping");
|
|
||||||
// reset velocity from gravity
|
// reset velocity from gravity
|
||||||
if (-Vector3.Dot(Physics.Gravity.Normalized, velocity) < 0 &&
|
if (-Vector3.Dot(Physics.Gravity.Normalized, velocity) < 0 &&
|
||||||
Vector3.Dot(velocity, traceGround.hitNormal) < -0.1)
|
Vector3.Dot(velocity, traceGround.hitNormal) < -0.1)
|
||||||
@@ -717,6 +733,8 @@ namespace Game
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (onGround)
|
||||||
|
{
|
||||||
// ground friction
|
// ground friction
|
||||||
{
|
{
|
||||||
float currentSpeed = velocity.Length;
|
float currentSpeed = velocity.Length;
|
||||||
@@ -740,13 +758,41 @@ namespace Game
|
|||||||
}
|
}
|
||||||
else // air movement
|
else // air movement
|
||||||
{
|
{
|
||||||
var wishspeed = wishVelocity.Length;
|
float wishspeed = wishVelocity.Length;
|
||||||
if (wishspeed > maxAirSpeed)
|
if (wishspeed > maxAirSpeed)
|
||||||
wishspeed = maxAirSpeed;
|
wishspeed = maxAirSpeed;
|
||||||
|
|
||||||
|
float wishspeedAirControl = wishspeed;
|
||||||
|
|
||||||
|
if (airAcceleration != 0)
|
||||||
|
{
|
||||||
|
// Q2+ air acceleration
|
||||||
|
float accel = airAcceleration;
|
||||||
|
if (Vector3.Dot(velocity, wishVelocity.Normalized) < 0)
|
||||||
|
accel = airStopAcceleration;
|
||||||
|
|
||||||
|
if (airStrafeAcceleration != 0 && Mathf.Abs(moveDirection.X) > 0 && moveDirection.Y == 0)
|
||||||
|
{
|
||||||
|
// only strafe movement
|
||||||
|
if (wishspeed > maxAirStrafeSpeed)
|
||||||
|
wishspeed = maxAirStrafeSpeed;
|
||||||
|
|
||||||
|
accel = airStrafeAcceleration;
|
||||||
|
}
|
||||||
|
|
||||||
|
ApplyAcceleration(ref velocity, wishVelocity.Normalized, wishspeed, float.MaxValue, accel);
|
||||||
|
}
|
||||||
|
|
||||||
|
// QW air acceleration
|
||||||
if (strafeAcceleration != 0f)
|
if (strafeAcceleration != 0f)
|
||||||
|
{
|
||||||
ApplyAcceleration(ref velocity, wishVelocity.Normalized, wishspeed, maxAirStrafeSpeed,
|
ApplyAcceleration(ref velocity, wishVelocity.Normalized, wishspeed, maxAirStrafeSpeed,
|
||||||
strafeAcceleration);
|
strafeAcceleration);
|
||||||
|
}
|
||||||
|
|
||||||
|
// air control while holding forward/back buttons
|
||||||
|
//if (airControl != 0 && moveDirection.X == 0 && Mathf.Abs(moveDirection.Y) > 0)
|
||||||
|
// PM_Aircontrol(wishdir, wishspeedAirControl);
|
||||||
|
|
||||||
// apply gravity
|
// apply gravity
|
||||||
velocity += Physics.Gravity * Time.DeltaTime;
|
velocity += Physics.Gravity * Time.DeltaTime;
|
||||||
|
|||||||
Reference in New Issue
Block a user