revamped jump
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=43 format=3 uid="uid://bei4nhkf8lwdo"]
|
||||
[gd_scene load_steps=44 format=3 uid="uid://bei4nhkf8lwdo"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bbbrf5ckydfna" path="res://player_controller/Scripts/PlayerController.cs" id="1_poq2x"]
|
||||
[ext_resource type="Curve" uid="uid://c2a8soliruf35" path="res://systems/dash/dash_time_dilation.tres" id="2_2q0ik"]
|
||||
@ -22,6 +22,7 @@
|
||||
[ext_resource type="PackedScene" uid="uid://0ysqmqphq6mq" path="res://systems/head/head_system.tscn" id="11_rxwoh"]
|
||||
[ext_resource type="Resource" uid="uid://d2r0ur8k3cuu3" path="res://systems/inputs/base_mode/dash.tres" id="12_34snm"]
|
||||
[ext_resource type="Script" uid="uid://b6k73aj5povgv" path="res://player_controller/Scripts/FieldOfView.cs" id="12_m2mxi"]
|
||||
[ext_resource type="Resource" uid="uid://55b0dsvioj08" path="res://systems/inputs/base_mode/jump_pressed.tres" id="13_nob5r"]
|
||||
[ext_resource type="Shape3D" uid="uid://keseacdcooot" path="res://player_controller/resources/PlayerShape.tres" id="13_r7i3q"]
|
||||
[ext_resource type="Resource" uid="uid://bw5k2gsv3jqcv" path="res://systems/inputs/base_mode/throw.tres" id="16_nob5r"]
|
||||
[ext_resource type="Script" uid="uid://b5nk6ntlps3x0" path="res://systems/inputs/input_system.gd" id="16_v31n3"]
|
||||
@ -50,8 +51,10 @@ blend_mode = 1
|
||||
[node name="Player" type="CharacterBody3D"]
|
||||
script = ExtResource("1_poq2x")
|
||||
AccelerationSpeedFactorFloor = 3.0
|
||||
Weight = 3.5
|
||||
StartVelocity = 0.7
|
||||
Weight = 5.0
|
||||
SimpleJumpStartVelocity = 7.0
|
||||
HangTimeInFrames = 3
|
||||
GravityLesseningFactorUpward = 2.5
|
||||
JumpFromDashSpeedFactor = 4.0
|
||||
WallHugHorizontalDeceleration = 3.0
|
||||
MaxJumpBoostAfterDashing = 0.7
|
||||
@ -69,10 +72,11 @@ rotate_floorplane = ExtResource("5_4u7i3")
|
||||
aim_down = ExtResource("8_obsfv")
|
||||
aim_pressed = ExtResource("9_nob5r")
|
||||
aim_released = ExtResource("8_lhb11")
|
||||
jump = ExtResource("10_4u7i3")
|
||||
jump_pressed = ExtResource("13_nob5r")
|
||||
empower_down = ExtResource("10_nodcl")
|
||||
empower_released = ExtResource("11_ruloh")
|
||||
aim_canceled = ExtResource("9_5p2qc")
|
||||
jump = ExtResource("10_4u7i3")
|
||||
hit = ExtResource("11_cresl")
|
||||
dash = ExtResource("12_34snm")
|
||||
throw = ExtResource("16_nob5r")
|
||||
@ -174,7 +178,7 @@ StraightThrowDuration = 0.05
|
||||
wait_time = 0.2
|
||||
one_shot = true
|
||||
|
||||
[node name="DashCooldown" type="Timer" parent="."]
|
||||
[node name="PowerCooldown" type="Timer" parent="."]
|
||||
wait_time = 2.0
|
||||
one_shot = true
|
||||
|
||||
@ -411,12 +415,6 @@ to = NodePath("../Airborne/Falling")
|
||||
event = &"falling"
|
||||
delay_in_seconds = "0.0"
|
||||
|
||||
[node name="OnGrounded" type="Node" parent="StateChart/Root/Movement"]
|
||||
script = ExtResource("28_n7qhm")
|
||||
to = NodePath("../Grounded")
|
||||
event = &"grounded"
|
||||
delay_in_seconds = "0.0"
|
||||
|
||||
[node name="OnMantle" type="Node" parent="StateChart/Root/Movement"]
|
||||
script = ExtResource("28_n7qhm")
|
||||
to = NodePath("../Mantling")
|
||||
@ -449,11 +447,17 @@ script = ExtResource("27_34snm")
|
||||
|
||||
[node name="Jump" type="Node" parent="StateChart/Root/Movement"]
|
||||
script = ExtResource("26_infe6")
|
||||
initial_state = NodePath("Normal")
|
||||
initial_state = NodePath("SimpleJump")
|
||||
|
||||
[node name="Normal" type="Node" parent="StateChart/Root/Movement/Jump"]
|
||||
[node name="SimpleJump" type="Node" parent="StateChart/Root/Movement/Jump"]
|
||||
script = ExtResource("27_34snm")
|
||||
|
||||
[node name="OnJumpEnded" type="Node" parent="StateChart/Root/Movement/Jump/SimpleJump"]
|
||||
script = ExtResource("28_n7qhm")
|
||||
to = NodePath("../../../Airborne/DoubleJumpEnabled")
|
||||
event = &"jump_ended"
|
||||
delay_in_seconds = "0.0"
|
||||
|
||||
[node name="Double" type="Node" parent="StateChart/Root/Movement/Jump"]
|
||||
script = ExtResource("27_34snm")
|
||||
|
||||
@ -465,7 +469,7 @@ script = ExtResource("27_34snm")
|
||||
|
||||
[node name="OnJump" type="Node" parent="StateChart/Root/Movement/Grounded"]
|
||||
script = ExtResource("28_n7qhm")
|
||||
to = NodePath("../../Airborne/DoubleJumpEnabled")
|
||||
to = NodePath("../../Jump/SimpleJump")
|
||||
event = &"jump"
|
||||
delay_in_seconds = "0.0"
|
||||
|
||||
@ -489,6 +493,12 @@ initial_state = NodePath("CoyoteEnabled")
|
||||
script = ExtResource("41_ruloh")
|
||||
default_state = NodePath("../CoyoteEnabled")
|
||||
|
||||
[node name="OnGrounded" type="Node" parent="StateChart/Root/Movement/Airborne"]
|
||||
script = ExtResource("28_n7qhm")
|
||||
to = NodePath("../../Grounded")
|
||||
event = &"grounded"
|
||||
delay_in_seconds = "0.0"
|
||||
|
||||
[node name="OnWallHug" type="Node" parent="StateChart/Root/Movement/Airborne"]
|
||||
script = ExtResource("28_n7qhm")
|
||||
to = NodePath("../../OnWall/Hugging")
|
||||
@ -500,7 +510,7 @@ script = ExtResource("27_34snm")
|
||||
|
||||
[node name="OnJump" type="Node" parent="StateChart/Root/Movement/Airborne/CoyoteEnabled"]
|
||||
script = ExtResource("28_n7qhm")
|
||||
to = NodePath("../../DoubleJumpEnabled")
|
||||
to = NodePath("../../../Jump/SimpleJump")
|
||||
event = &"jump"
|
||||
delay_in_seconds = "0.0"
|
||||
|
||||
@ -591,7 +601,9 @@ delay_in_seconds = "0.0"
|
||||
[connection signal="input_empower_down" from="InputController" to="." method="OnInputEmpowerDown"]
|
||||
[connection signal="input_empower_released" from="InputController" to="." method="OnInputEmpowerReleased"]
|
||||
[connection signal="input_hit" from="InputController" to="." method="OnInputHitPressed"]
|
||||
[connection signal="input_jump" from="InputController" to="." method="OnInputJumpPressed"]
|
||||
[connection signal="input_jump_ended" from="InputController" to="." method="OnInputJumpEnded"]
|
||||
[connection signal="input_jump_ongoing" from="InputController" to="." method="OnInputJumpOngoing"]
|
||||
[connection signal="input_jump_started" from="InputController" to="." method="OnInputJumpStarted"]
|
||||
[connection signal="input_move" from="InputController" to="." method="OnInputMove"]
|
||||
[connection signal="input_rotate_floorplane" from="InputController" to="." method="OnInputRotateFloorplane"]
|
||||
[connection signal="input_rotate_y" from="InputController" to="." method="OnInputRotateY"]
|
||||
|
@ -31,7 +31,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
public WallHugSystem WallHugSystem;
|
||||
public PlayerUi PlayerUi;
|
||||
public TextureRect DashIndicator;
|
||||
public ColorRect DashCooldownIndicator;
|
||||
public ColorRect PowerCooldownIndicator;
|
||||
|
||||
private bool _movementEnabled = true;
|
||||
|
||||
@ -52,7 +52,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
private Timer _coyoteTimer;
|
||||
private Timer _timeScaleAimInAirTimer;
|
||||
private Timer _timeAfterDashingTimer;
|
||||
private Timer _dashCooldownTimer;
|
||||
private Timer _powerCooldownTimer;
|
||||
private Timer _empowerTimeDownscale;
|
||||
|
||||
[ExportCategory("Movement")]
|
||||
@ -68,7 +68,21 @@ public partial class PlayerController : CharacterBody3D
|
||||
public float DecelerationSpeedFactorAir = 1.0f;
|
||||
[Export(PropertyHint.Range, "0,10,0.01,or_greater")]
|
||||
public float Weight { get; set; } = 3.0f;
|
||||
|
||||
// Jump
|
||||
[ExportGroup("Jump")]
|
||||
|
||||
// Simple jump
|
||||
[ExportSubgroup("Simple jump")]
|
||||
[Export(PropertyHint.Range, "0,100,1,or_greater")]
|
||||
public float SimpleJumpStartVelocity { get; set; } = 3.0f;
|
||||
[Export(PropertyHint.Range, "0,10,1,or_greater")]
|
||||
public int HangTimeInFrames { get; set; } = 5;
|
||||
[Export(PropertyHint.Range, "1,10,0.1,or_greater")]
|
||||
public float GravityLesseningFactorUpward { get; set; } = 3f;
|
||||
|
||||
// Other jump
|
||||
[ExportSubgroup("Other jump")]
|
||||
[Export(PropertyHint.Range, "0,2,0.01,or_greater")]
|
||||
public float StartVelocity { get; set; } = 1.0f;
|
||||
[Export(PropertyHint.Range, "0.1,10,0.1,or_greater")]
|
||||
@ -138,6 +152,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
private StateChartState _movHanging;
|
||||
private StateChartState _airborne;
|
||||
private StateChartState _coyoteEnabled;
|
||||
private StateChartState _simpleJump;
|
||||
private StateChartState _doubleJumpEnabled;
|
||||
private StateChartState _onWall;
|
||||
private StateChartState _onWallHugCanceled;
|
||||
@ -155,8 +170,8 @@ public partial class PlayerController : CharacterBody3D
|
||||
TweenQueueSystem = GetNode<TweenQueueSystem>("TweenQueueSystem");
|
||||
PlayerUi = GetNode<PlayerUi>("UI");
|
||||
// DashIndicator = GetNode<TextureRect>("%DashIndicator");
|
||||
DashCooldownIndicator = GetNode<ColorRect>("%DashCooldownIndicator");
|
||||
DashCooldownIndicator.Visible = false;
|
||||
PowerCooldownIndicator = GetNode<ColorRect>("%DashCooldownIndicator");
|
||||
PowerCooldownIndicator.Visible = false;
|
||||
EmpoweredActionsLeft = MaxNumberOfDashActions;
|
||||
_targetSpeed = WalkSpeed;
|
||||
|
||||
@ -214,6 +229,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
_movHanging = StateChartState.Of(GetNode("StateChart/Root/Movement/OnWall/Hanging"));
|
||||
_airborne = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne"));
|
||||
_coyoteEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/CoyoteEnabled"));
|
||||
_simpleJump = StateChartState.Of(GetNode("StateChart/Root/Movement/Jump/SimpleJump"));
|
||||
_doubleJumpEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/DoubleJumpEnabled"));
|
||||
_onWall = StateChartState.Of(GetNode("StateChart/Root/Movement/OnWall"));
|
||||
_onWallHugging = StateChartState.Of(GetNode("StateChart/Root/Movement/OnWall/Hugging"));
|
||||
@ -222,7 +238,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
_falling = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/Falling"));
|
||||
// State timers
|
||||
_coyoteTimer = GetNode<Timer>("CoyoteTime");
|
||||
_dashCooldownTimer = GetNode<Timer>("DashCooldown");
|
||||
_powerCooldownTimer = GetNode<Timer>("PowerCooldown");
|
||||
_timeScaleAimInAirTimer = GetNode<Timer>("TimeScaleAimInAir");
|
||||
_timeAfterDashingTimer = GetNode<Timer>("TimeAfterDashing");
|
||||
_empowerTimeDownscale = GetNode<Timer>("EmpowerTimeDownscale");
|
||||
@ -295,33 +311,125 @@ public partial class PlayerController : CharacterBody3D
|
||||
// _empowerOff.StateEntered += EmpowerStopped;
|
||||
// _empowerTimeDownscale.Timeout += EmpowerTimerTimeout;
|
||||
|
||||
_powerFull.StateExited += StartDashCooldown;
|
||||
_powerRecharging.StateEntered += StartDashCooldown;
|
||||
_powerFull.StateEntered += StopDashCooldown;
|
||||
_dashCooldownTimer.Timeout += DashCooldownExpired;
|
||||
_powerFull.StateExited += StartPowerCooldown;
|
||||
_powerRecharging.StateEntered += StartPowerCooldown;
|
||||
_powerFull.StateEntered += StopPowerCooldown;
|
||||
_powerCooldownTimer.Timeout += PowerCooldownExpired;
|
||||
_powerRecharging.StateProcessing += PowerRecharging;
|
||||
_powerExpired.StateProcessing += PowerRecharging;
|
||||
|
||||
_simpleJump.StateEntered += OnSimpleJumpStarted;
|
||||
_simpleJump.StatePhysicsProcessing += HandleSimpleJump;
|
||||
_simpleJump.StateExited += OnSimpleJumpEnded;
|
||||
}
|
||||
|
||||
public void OnInputJumpStarted()
|
||||
{
|
||||
if (CanMantle())
|
||||
{
|
||||
Mantle();
|
||||
return;
|
||||
}
|
||||
|
||||
// if (_grounded.Active || _coyoteEnabled.Active)
|
||||
// {
|
||||
// if (_empowerOn.Active && CanPerformEmpoweredAction())
|
||||
// {
|
||||
// PerformEmpoweredAction();
|
||||
// PerformJump(JumpTypes.JumpFromDash);
|
||||
// _playerState.SendEvent("megajump");
|
||||
// }
|
||||
// }
|
||||
// else if (_doubleJumpEnabled.Active)
|
||||
// if (_empowerOn.Active && CanPerformEmpoweredAction())
|
||||
// {
|
||||
// PerformEmpoweredAction();
|
||||
// PerformJump(JumpTypes.JumpFromDash);
|
||||
// _playerState.SendEvent("megajump");
|
||||
// }
|
||||
// else
|
||||
// PerformJump(JumpTypes.DoubleJump);
|
||||
// else if (_onWall.Active)
|
||||
// JumpFromWall(_empowerOn.Active);
|
||||
|
||||
_playerState.SendEvent("jump");
|
||||
}
|
||||
|
||||
public void OnInputJumpOngoing()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnInputJumpEnded()
|
||||
{
|
||||
_playerState.SendEvent("jump_ended");
|
||||
}
|
||||
|
||||
private int _framesSinceJumpAtApex = 0;
|
||||
public void OnSimpleJumpStarted()
|
||||
{
|
||||
_framesSinceJumpAtApex = 0;
|
||||
|
||||
Velocity = new Vector3(
|
||||
x: Velocity.X,
|
||||
y: SimpleJumpStartVelocity,
|
||||
z: Velocity.Z);
|
||||
}
|
||||
|
||||
public void HandleSimpleJump(float delta)
|
||||
{
|
||||
// Hang time at the top of the jump
|
||||
if (Velocity.Y <= Mathf.Epsilon)
|
||||
{
|
||||
_framesSinceJumpAtApex++;
|
||||
Velocity = new Vector3(
|
||||
x: Velocity.X,
|
||||
y: 0,
|
||||
z: Velocity.Z);
|
||||
}
|
||||
|
||||
// Cancel gravity on jump apex
|
||||
var gravity = CalculateGravityForce() / GravityLesseningFactorUpward;
|
||||
var isAtApex = _framesSinceJumpAtApex > 0;
|
||||
if (isAtApex)
|
||||
{
|
||||
gravity = 0;
|
||||
}
|
||||
// Update velocity accordingly
|
||||
var newVerticalSpeed = Velocity.Y - gravity * delta;
|
||||
Velocity = new Vector3(
|
||||
x: Velocity.X,
|
||||
y: newVerticalSpeed,
|
||||
z: Velocity.Z);
|
||||
|
||||
|
||||
// Move back to Airborne state management when starting to go down again
|
||||
if (_framesSinceJumpAtApex > HangTimeInFrames)
|
||||
_playerState.SendEvent("jump_ended");
|
||||
}
|
||||
|
||||
public void OnSimpleJumpEnded()
|
||||
{
|
||||
}
|
||||
|
||||
public void PowerRecharging(float delta)
|
||||
{
|
||||
var progress = (float) (_dashCooldownTimer.TimeLeft / _dashCooldownTimer.WaitTime);
|
||||
DashCooldownIndicator.SetSize(new Vector2(100 * progress, 10));
|
||||
var progress = (float) (_powerCooldownTimer.TimeLeft / _powerCooldownTimer.WaitTime);
|
||||
PowerCooldownIndicator.SetSize(new Vector2(100 * progress, 10));
|
||||
}
|
||||
|
||||
public void StartDashCooldown()
|
||||
public void StartPowerCooldown()
|
||||
{
|
||||
_dashCooldownTimer.Start();
|
||||
DashCooldownIndicator.Visible = true;
|
||||
_powerCooldownTimer.Start();
|
||||
PowerCooldownIndicator.Visible = true;
|
||||
}
|
||||
|
||||
public void StopDashCooldown()
|
||||
public void StopPowerCooldown()
|
||||
{
|
||||
_dashCooldownTimer.Stop();
|
||||
DashCooldownIndicator.Visible = false;
|
||||
_powerCooldownTimer.Stop();
|
||||
PowerCooldownIndicator.Visible = false;
|
||||
}
|
||||
|
||||
public void DashCooldownExpired()
|
||||
public void PowerCooldownExpired()
|
||||
{
|
||||
EmpoweredActionsLeft += 1;
|
||||
var eventToSend = EmpoweredActionsLeft == MaxNumberOfDashActions ? "fully_charged" : "recharge";
|
||||
@ -372,38 +480,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
OnWeaponThrown();
|
||||
}
|
||||
}
|
||||
public void OnInputJumpPressed()
|
||||
{
|
||||
if (CanMantle())
|
||||
{
|
||||
Mantle();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_grounded.Active || _coyoteEnabled.Active)
|
||||
if (_empowerOn.Active && CanPerformEmpoweredAction())
|
||||
{
|
||||
PerformEmpoweredAction();
|
||||
PerformJump(JumpTypes.JumpFromDash);
|
||||
_playerState.SendEvent("megajump");
|
||||
}
|
||||
else
|
||||
PerformJump(JumpTypes.SimpleJump);
|
||||
else if (_doubleJumpEnabled.Active)
|
||||
if (_empowerOn.Active && CanPerformEmpoweredAction())
|
||||
{
|
||||
PerformEmpoweredAction();
|
||||
PerformJump(JumpTypes.JumpFromDash);
|
||||
_playerState.SendEvent("megajump");
|
||||
}
|
||||
else
|
||||
PerformJump(JumpTypes.DoubleJump);
|
||||
else if (_onWall.Active)
|
||||
JumpFromWall(_empowerOn.Active);
|
||||
|
||||
_playerState.SendEvent("jump");
|
||||
|
||||
}
|
||||
public void OnInputDashPressed()
|
||||
{
|
||||
_playerState.SendEvent("dash");
|
||||
@ -452,15 +528,8 @@ public partial class PlayerController : CharacterBody3D
|
||||
// Stateful logic /////////
|
||||
///////////////////////////
|
||||
|
||||
// Simple states
|
||||
public void OnGrounded()
|
||||
{
|
||||
RestoreEmpoweredActions();
|
||||
}
|
||||
|
||||
private void RestoreEmpoweredActions()
|
||||
{
|
||||
// EmpoweredActionsLeft = MaxNumberOfDashActions;
|
||||
_isWallJumpAvailable = true;
|
||||
}
|
||||
|
||||
@ -508,13 +577,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
var jumpVector = (effectiveJumpDirection.Normalized() + Vector3.Up).Normalized();
|
||||
if (jumpType == JumpTypes.DoubleJump)
|
||||
_canDash = false;
|
||||
|
||||
// var proportionOfTimeGone = _timeAfterDashingTimer.TimeLeft / _timeAfterDashingTimer.WaitTime;
|
||||
// var actualBoost = 1 + MaxJumpBoostAfterDashing * proportionOfTimeGone;
|
||||
// var makeItDouble = actualBoost > 1;
|
||||
// if (makeItDouble && jumpType == MoveSystem.JumpTypes.SimpleJump)
|
||||
// jumpType = MoveSystem.JumpTypes.DoubleJump; // convert simple jump to double if done right after a dash
|
||||
// _timeAfterDashingTimer.Stop();
|
||||
|
||||
bool doesCapsuleHaveCrouchingHeight = CapsuleCollider.IsCrouchingHeight();
|
||||
bool isPlayerDead = HealthSystem.IsDead();
|
||||
@ -668,8 +730,6 @@ public partial class PlayerController : CharacterBody3D
|
||||
|
||||
// Weapon planted anywhere else
|
||||
_playerState.SendEvent("dash_ended");
|
||||
if (isOnFloorCustom())
|
||||
RestoreEmpoweredActions(); // Make sure to restore actions if we're still on the ground
|
||||
}
|
||||
public void OnWeaponThrown()
|
||||
{
|
||||
@ -858,7 +918,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
IsCapsuleHeightLessThanNormal = CapsuleCollider.IsCapsuleHeightLessThanNormal(),
|
||||
CurrentSpeedGreaterThanWalkSpeed = false,
|
||||
BetweenCrouchingAndNormalHeight = CapsuleCollider.IsBetweenCrouchingAndNormalHeight(),
|
||||
Delta = (float)delta
|
||||
Delta = delta
|
||||
};
|
||||
StairsSystem.SlideCameraSmoothBackToOrigin(slideCameraParams);
|
||||
}
|
||||
@ -876,7 +936,7 @@ public partial class PlayerController : CharacterBody3D
|
||||
FieldOfView.FovParameters fovParams = new FieldOfView.FovParameters
|
||||
{
|
||||
IsCrouchingHeight = CapsuleCollider.IsCrouchingHeight(),
|
||||
Delta = (float)delta,
|
||||
Delta = delta,
|
||||
SprintSpeed = WalkSpeed,
|
||||
Velocity = Velocity
|
||||
};
|
||||
|
Reference in New Issue
Block a user