added projectile targeting anticipation
This commit is contained in:
parent
eea6830534
commit
7846f1a068
3 changed files with 68 additions and 24 deletions
|
|
@ -36,7 +36,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
public float WaterAccel { get; set; } = 1200.0f;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:s")]
|
||||
public float JumpAscentMaxTime { get; set; } = 0.2f;
|
||||
public float JumpAscentMaxTime { get; set; } = 0.25f;
|
||||
|
||||
[Export(PropertyHint.None, "suffix:px/s")]
|
||||
public float JumpAscentSpeed { get; set; } = 200.0f;
|
||||
|
|
@ -62,9 +62,9 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
[Export] public TileMapLayer WaterTileMap { get; set; } = null!;
|
||||
|
||||
private ulong MaxInputBufferTimeMicroseconds => (ulong)(MaxInputBufferTime * 1_000_000);
|
||||
private float _jumpAscentRemainingTime;
|
||||
private bool _isJumping;
|
||||
private float _jumpAllowedTime;
|
||||
public float JumpAscentRemainingTime { get; private set; }
|
||||
public bool IsJumping { get; private set; }
|
||||
public float JumpAllowedTime { get; private set; }
|
||||
private Vector2 _currentDirection = Vector2.Zero;
|
||||
private bool _isFacingRight = true;
|
||||
private AnimationNodeStateMachinePlayback _playback = null!;
|
||||
|
|
@ -150,12 +150,12 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
}
|
||||
|
||||
// Move up while holding jump
|
||||
if (_jumpAscentRemainingTime > 0)
|
||||
if (JumpAscentRemainingTime > 0)
|
||||
{
|
||||
velocity.Y = -JumpAscentSpeed;
|
||||
_jumpAscentRemainingTime -= deltaF;
|
||||
if (_jumpAscentRemainingTime < 0)
|
||||
velocity += GetGravity() * -_jumpAscentRemainingTime;
|
||||
JumpAscentRemainingTime -= deltaF;
|
||||
if (JumpAscentRemainingTime < 0)
|
||||
velocity += GetGravity() * -JumpAscentRemainingTime;
|
||||
}
|
||||
else if (!IsOnFloor() && !_isInWater)
|
||||
{
|
||||
|
|
@ -168,7 +168,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
velocity += Physics.DragForce(-velocity, 0.02f) * deltaF;
|
||||
}
|
||||
// Drag while in air
|
||||
else if (!IsOnFloor() && _jumpAscentRemainingTime <= 0)
|
||||
else if (!IsOnFloor() && JumpAscentRemainingTime <= 0)
|
||||
{
|
||||
velocity += Physics.DragForce(-velocity, 0.009f) * deltaF;
|
||||
}
|
||||
|
|
@ -191,14 +191,14 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
}
|
||||
MoveAndSlide();
|
||||
|
||||
_jumpAllowedTime = Mathf.Max(0, _jumpAllowedTime - deltaF);
|
||||
JumpAllowedTime = Mathf.Max(0, JumpAllowedTime - deltaF);
|
||||
if (IsOnFloor())
|
||||
_jumpAllowedTime = LateJumpTimeLimit;
|
||||
JumpAllowedTime = LateJumpTimeLimit;
|
||||
|
||||
if (IsOnCeiling())
|
||||
{
|
||||
_isJumping = false;
|
||||
_jumpAscentRemainingTime = 0.0f;
|
||||
IsJumping = false;
|
||||
JumpAscentRemainingTime = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -266,7 +266,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
}
|
||||
else if (
|
||||
input.Event.IsPressed()
|
||||
&& _jumpAllowedTime > 0
|
||||
&& JumpAllowedTime > 0
|
||||
&& (!IsOnFloor() || !IsInputVecDown(input.Direction)))
|
||||
{
|
||||
inputFound = true;
|
||||
|
|
@ -277,7 +277,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
inputFound = true;
|
||||
WallJump();
|
||||
}
|
||||
else if (input.Event.IsReleased() && _isJumping)
|
||||
else if (input.Event.IsReleased() && IsJumping)
|
||||
{
|
||||
JumpCut();
|
||||
}
|
||||
|
|
@ -304,23 +304,23 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
private void GroundJump()
|
||||
{
|
||||
AdjustFacing();
|
||||
_jumpAllowedTime = 0.0f;
|
||||
_jumpAscentRemainingTime = JumpAscentMaxTime;
|
||||
_isJumping = true;
|
||||
JumpAllowedTime = 0.0f;
|
||||
JumpAscentRemainingTime = JumpAscentMaxTime;
|
||||
IsJumping = true;
|
||||
}
|
||||
|
||||
private void WallJump()
|
||||
{
|
||||
AdjustFacing();
|
||||
_jumpAllowedTime = 0.0f;
|
||||
JumpAllowedTime = 0.0f;
|
||||
Velocity += GetWallNormal() * 200.0f;
|
||||
Velocity = Velocity with { Y = Mathf.Min(0, Velocity.Y) };
|
||||
}
|
||||
|
||||
private void JumpCut()
|
||||
{
|
||||
_isJumping = false;
|
||||
_jumpAscentRemainingTime = 0.0f;
|
||||
IsJumping = false;
|
||||
JumpAscentRemainingTime = 0.0f;
|
||||
// Jump cut only once, if we're still moving up
|
||||
if (Velocity.Y < 0)
|
||||
Velocity = Velocity with { Y = Velocity.Y * 0.1f };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue