Q2 air acceleration, jump fix

This commit is contained in:
GoaLitiuM
2021-09-13 19:35:23 +03:00
parent 76cb9c2070
commit eff5b555ba

View File

@@ -581,6 +581,8 @@ namespace Game
[ReadOnly] public bool onGround = false;
/*
// QW
private const float friction = 4f;
private const float stopspeed = 100f;
private const float accelerationGround = 10f;
@@ -588,13 +590,31 @@ namespace Game
private const float maxAirSpeed = 320f;
private const float maxAirStrafeSpeed = 30f; //Q2+
private const float airAcceleration = 0.4f * 0f; //Q2+
private const float airStopAcceleration = 2.5f * 0f; //Q2+
private const float airStrafeAcceleration = 70f * 0f; //CPM?
private const float airAcceleration = 0f; //Q2+
private const float airStopAcceleration = 0f; //Q2+
private const float airStrafeAcceleration = 0f; //CPM?
private const float strafeAcceleration = 10f; //QW
private const float airControl = 0f; //CPM
private const float stepSize = 16f;
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 jumped = false;
@@ -678,7 +698,6 @@ namespace Game
// TODO: snap to ground here
bool jumpAction = InputManager.GetAction("Jump");
if (jumped && !jumpAction)
@@ -686,37 +705,36 @@ namespace Game
else if (jumped && Time.GameTime - lastJumped >= autoJumpTime)
jumped = false; // jump timeout
if (onGround)
// jump
if (onGround && jumpAction && !jumped)
{
// jump
if (jumpAction && !jumped)
// reset velocity from gravity
if (-Vector3.Dot(Physics.Gravity.Normalized, velocity) < 0 &&
Vector3.Dot(velocity, traceGround.hitNormal) < -0.1)
{
Console.Print("jumping");
// reset velocity from gravity
if (-Vector3.Dot(Physics.Gravity.Normalized, velocity) < 0 &&
Vector3.Dot(velocity, traceGround.hitNormal) < -0.1)
{
velocity = Vector3.ProjectOnPlane(velocity, traceGround.hitNormal);
}
velocity += Vector3.Up * jumpVelocity;
onGround = false;
jumped = true;
lastJumped = Time.GameTime;
if (JumpLandSound != null && JumpLandSound.IsLoaded)
{
var audioSource = new AudioSource();
audioSource.Clip = JumpLandSound;
audioSource.Position = rootActor.Position; //new Vector3(-350, 176, 61);//rootActor.Position;
audioSource.Parent = Actor.Parent;
audioSource.Pitch = 1f;
audioSource.Play();
Destroy(audioSource, JumpLandSound.Length);
}
velocity = Vector3.ProjectOnPlane(velocity, traceGround.hitNormal);
}
velocity += Vector3.Up * jumpVelocity;
onGround = false;
jumped = true;
lastJumped = Time.GameTime;
if (JumpLandSound != null && JumpLandSound.IsLoaded)
{
var audioSource = new AudioSource();
audioSource.Clip = JumpLandSound;
audioSource.Position = rootActor.Position; //new Vector3(-350, 176, 61);//rootActor.Position;
audioSource.Parent = Actor.Parent;
audioSource.Pitch = 1f;
audioSource.Play();
Destroy(audioSource, JumpLandSound.Length);
}
}
if (onGround)
{
// ground friction
{
float currentSpeed = velocity.Length;
@@ -740,13 +758,41 @@ namespace Game
}
else // air movement
{
var wishspeed = wishVelocity.Length;
float wishspeed = wishVelocity.Length;
if (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)
{
ApplyAcceleration(ref velocity, wishVelocity.Normalized, wishspeed, maxAirStrafeSpeed,
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
velocity += Physics.Gravity * Time.DeltaTime;