gd: added the drop action. Set up state managed coyote time, jump, double jump and overall movement.
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
using Godot;
|
||||
using Movementtests.player_controller.Scripts;
|
||||
using RustyOptions;
|
||||
|
||||
namespace Movementtests.systems;
|
||||
|
||||
@ -38,8 +39,6 @@ public partial class MoveSystem : Node3D
|
||||
[Export(PropertyHint.Range, "0,5,0.1,or_greater")]
|
||||
public float DoubleJumpSpeedFactor { get; set; } = 2f;
|
||||
|
||||
public bool CanDoubleJump { get; set; } = true;
|
||||
private float _lastFrameWasOnFloor = -Mathf.Inf;
|
||||
|
||||
private Gravity _gravity;
|
||||
private CharacterBody3D _parent;
|
||||
@ -81,12 +80,6 @@ public partial class MoveSystem : Node3D
|
||||
y: _parent.Velocity.Y - (_gravity.CalculateGravityForce() * (float)delta),
|
||||
z: _parent.Velocity.Z);
|
||||
}
|
||||
|
||||
if (isOnFloor)
|
||||
{
|
||||
_lastFrameWasOnFloor = Engine.GetPhysicsFrames();
|
||||
CanDoubleJump = true;
|
||||
}
|
||||
|
||||
// The code below is required to quickly adjust player's position on Y-axis when there's a ceiling on the
|
||||
// trajectory of player's jump and player is standing
|
||||
@ -174,29 +167,33 @@ public partial class MoveSystem : Node3D
|
||||
}
|
||||
}
|
||||
|
||||
public void Jump(bool isOnFloor)
|
||||
public void Jump(bool isDoubleJump)
|
||||
{
|
||||
var jumpForce = isDoubleJump
|
||||
? _gravity.CalculateJumpForce() * DoubleJumpSpeedFactor
|
||||
: _gravity.CalculateJumpForce();
|
||||
|
||||
_parent.Velocity = new Vector3(
|
||||
x: _parent.Velocity.X,
|
||||
y: jumpForce,
|
||||
z: _parent.Velocity.Z);
|
||||
}
|
||||
|
||||
public bool CanMantle()
|
||||
{
|
||||
var mantleLocationResult = _mantleSystem.FindMantleInFrontOfPlayer();
|
||||
return mantleLocationResult.IsSome(out _);
|
||||
}
|
||||
|
||||
public Option<Tween> Mantle()
|
||||
{
|
||||
var mantleLocationResult = _mantleSystem.FindMantleInFrontOfPlayer();
|
||||
if (mantleLocationResult.IsSome(out var mantleLocation))
|
||||
{
|
||||
var duration = 0.1f * mantleLocation.DistanceTo(_parent.Position);
|
||||
_tweenQueueSystem.QueueTween(mantleLocation, duration);
|
||||
var tween = _tweenQueueSystem.TweenToLocation(new TweenQueueSystem.TweenInputs(mantleLocation, duration));
|
||||
return tween.Some();
|
||||
}
|
||||
else if (isOnFloor)
|
||||
{
|
||||
_parent.Velocity = new Vector3(
|
||||
x: _parent.Velocity.X,
|
||||
y: _gravity.CalculateJumpForce(),
|
||||
z: _parent.Velocity.Z);
|
||||
}
|
||||
else if (CanDoubleJump)
|
||||
{
|
||||
CanDoubleJump = false;
|
||||
_parent.Velocity = new Vector3(
|
||||
x: _parent.Velocity.X,
|
||||
y: _gravity.CalculateJumpForce() * DoubleJumpSpeedFactor,
|
||||
z: _parent.Velocity.Z);
|
||||
}
|
||||
|
||||
return Option<Tween>.None;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user