player controller feel tweaks
This commit is contained in:
parent
b13828d8e1
commit
8ab8973894
3 changed files with 65 additions and 34 deletions
|
|
@ -21,13 +21,19 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
public float GroundedSpeedStopDecay { get; set; } = 0.005f;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:px/s")]
|
||||
public float WalkMaxSpeed { get; set; } = 110.0f;
|
||||
public float WalkMaxSpeed { get; set; } = 160.0f;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:px/s")]
|
||||
public float AirMaxSpeed { get; set; } = 160.0f;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:px/s")]
|
||||
public float WaterMaxSpeed { get; set; } = 180.0f;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:px/s²")]
|
||||
public float WalkAccel { get; set; } = 800.0f;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:px/s²")]
|
||||
public float AirAccel { get; set; } = 180.0f;
|
||||
public float AirAccel { get; set; } = 600.0f;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:px/s²")]
|
||||
public float WaterAccel { get; set; } = 1200.0f;
|
||||
|
|
@ -56,6 +62,8 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
|
||||
private ulong MaxInputBufferTimeMicroseconds => (ulong)(MaxInputBufferTime * 1_000_000);
|
||||
public bool IsJumping => !JumpTimer.IsStopped();
|
||||
public bool IsWallJumping => !WallJumpTimer.IsStopped();
|
||||
public bool IsDoingAnyJump => IsJumping || IsWallJumping;
|
||||
|
||||
/// The direction the player is currently holding.
|
||||
/// This vector's components should always be -1/0/1.
|
||||
|
|
@ -76,6 +84,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
[Node] private Area2D SubmersedSensor { get; set; } = null!;
|
||||
[Node] private Hitbox DashHitbox { get; set; } = null!;
|
||||
[Node] private Timer JumpTimer { get; set; } = null!;
|
||||
[Node] private Timer WallJumpTimer { get; set; } = null!;
|
||||
[Node] private Timer JumpAllowedTimer { get; set; } = null!;
|
||||
[Node] private Timer WaterJumpAllowedTimer { get; set; } = null!;
|
||||
[Node] private Timer DashTimer { get; set; } = null!;
|
||||
|
|
@ -139,6 +148,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
var deltaF = (float)delta;
|
||||
// Temporary copy of the velocity for easier editing.
|
||||
var velocity = Velocity;
|
||||
var dragAmount = 0f;
|
||||
|
||||
if (CanTurn) AdjustFacing();
|
||||
|
||||
|
|
@ -149,7 +159,24 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
// Water movement
|
||||
else if (IsInWater)
|
||||
{
|
||||
var velocityWasTooLarge = velocity.Length() > WaterMaxSpeed;
|
||||
velocity += _currentDirection.Normalized() * WaterAccel * deltaF;
|
||||
var velocityIsTooLarge = velocity.Length() > WaterMaxSpeed;
|
||||
if (velocityWasTooLarge && velocityIsTooLarge)
|
||||
{
|
||||
dragAmount = 0.015f;
|
||||
}
|
||||
|
||||
if (!velocityWasTooLarge && velocityIsTooLarge)
|
||||
{
|
||||
velocity = velocity.LimitLength(WaterMaxSpeed);
|
||||
}
|
||||
|
||||
if (!velocityIsTooLarge && _currentDirection.IsZeroApprox())
|
||||
{
|
||||
dragAmount = 0.1f;
|
||||
velocity = velocity.MoveToward(Vector2.Zero, 0.1f * deltaF);
|
||||
}
|
||||
}
|
||||
// Walking on the floor
|
||||
else if (IsOnFloor())
|
||||
|
|
@ -171,7 +198,18 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
// Air control
|
||||
else
|
||||
{
|
||||
velocity.X += Mathf.Sign(_currentDirection.X) * AirAccel * deltaF;
|
||||
var velocityWasTooLarge = Mathf.Abs(velocity.X) > AirMaxSpeed;
|
||||
|
||||
if (!velocityWasTooLarge || Mathf.Sign(_currentDirection.X) != Mathf.Sign(velocity.X))
|
||||
{
|
||||
velocity.X += Mathf.Sign(_currentDirection.X) * AirAccel * deltaF;
|
||||
}
|
||||
var velocityIsTooLarge = Mathf.Abs(velocity.X) > AirMaxSpeed;
|
||||
if (!velocityWasTooLarge && velocityIsTooLarge)
|
||||
{
|
||||
velocity.X = Mathf.Clamp(velocity.X, -AirMaxSpeed, AirMaxSpeed);
|
||||
}
|
||||
dragAmount = _currentDirection.IsZeroApprox() ? 0.015f : 0.009f;
|
||||
}
|
||||
|
||||
// Move up while holding jump
|
||||
|
|
@ -184,26 +222,8 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
velocity += GetGravity() * deltaF;
|
||||
}
|
||||
|
||||
if (DashTimer.IsStopped())
|
||||
{
|
||||
// Drag in water
|
||||
if (IsInWater)
|
||||
{
|
||||
if (_currentDirection.IsZeroApprox() || IsHoldingWall)
|
||||
{
|
||||
velocity += Physics.DragForce(-velocity, 0.2f) * deltaF;
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity += Physics.DragForce(-velocity, 0.015f) * deltaF;
|
||||
}
|
||||
}
|
||||
// Drag while in air
|
||||
else if (!IsOnFloor() && JumpTimer.IsStopped())
|
||||
{
|
||||
velocity += Physics.DragForce(-velocity, 0.009f) * deltaF;
|
||||
}
|
||||
}
|
||||
if (IsDoingAnyJump) dragAmount = 0f;
|
||||
velocity += Physics.DragForce(-velocity, dragAmount) * deltaF;
|
||||
|
||||
if (IsHoldingWall)
|
||||
{
|
||||
|
|
@ -364,7 +384,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
return true;
|
||||
|
||||
case { Action: Action.Jump, IsPressed: false }
|
||||
when IsJumping:
|
||||
when IsDoingAnyJump:
|
||||
JumpCut();
|
||||
return false;
|
||||
|
||||
|
|
@ -409,10 +429,20 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
|
||||
private void JumpCut()
|
||||
{
|
||||
JumpTimer.Stop();
|
||||
// Jump cut only once, if we're still moving up
|
||||
if (Velocity.Y < 0)
|
||||
Velocity = Velocity with { Y = Velocity.Y * 0.1f };
|
||||
if (!JumpTimer.IsStopped())
|
||||
{
|
||||
JumpTimer.Stop();
|
||||
// Jump cut only once, if we're still moving up
|
||||
if (Velocity.Y < 0)
|
||||
Velocity *= new Vector2(1f, 0.1f);
|
||||
}
|
||||
if (!WallJumpTimer.IsStopped())
|
||||
{
|
||||
WallJumpTimer.Stop();
|
||||
if (Velocity.Y < 0)
|
||||
Velocity *= new Vector2(1f, 0.1f);
|
||||
Velocity = Velocity.LimitLength(AirMaxSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
private void Attack()
|
||||
|
|
@ -494,11 +524,6 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
IHitboxOwner IProvide<IHitboxOwner>.
|
||||
Value() => this;
|
||||
|
||||
public enum Move
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnAttacked(Hurtbox hurtbox, in Attack attack)
|
||||
{
|
||||
GetAttacked(attack);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue