trying other setup

This commit is contained in:
2025-07-22 11:51:48 +02:00
parent 4c16ad4f9a
commit 9d29ec8ee4
6 changed files with 207 additions and 57 deletions

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=44 format=3 uid="uid://bei4nhkf8lwdo"]
[gd_scene load_steps=45 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"]
@ -14,6 +14,7 @@
[ext_resource type="PackedScene" uid="uid://wq1okogkhc5l" path="res://systems/mantle/mantle_system.tscn" id="8_qu4wy"]
[ext_resource type="Resource" uid="uid://7wm8ywvujwf" path="res://systems/inputs/base_mode/aim_cancel.tres" id="9_5p2qc"]
[ext_resource type="Script" uid="uid://bt0xv2q8iv1vn" path="res://player_controller/Scripts/Gravity.cs" id="9_lsueh"]
[ext_resource type="Resource" uid="uid://bebstkm608wxx" path="res://systems/inputs/base_mode/aim_pressed.tres" id="9_nob5r"]
[ext_resource type="Resource" uid="uid://bdit2jy5gbpts" path="res://systems/inputs/base_mode/jump.tres" id="10_4u7i3"]
[ext_resource type="Script" uid="uid://g8idirw62qe0" path="res://player_controller/Scripts/Bobbing.cs" id="10_7wk1w"]
[ext_resource type="Resource" uid="uid://b334rau1yxmm7" path="res://systems/inputs/base_mode/empower_down.tres" id="10_nodcl"]
@ -53,6 +54,7 @@ script = ExtResource("1_poq2x")
TimeScaleAimInAir = 0.15
MaxJumpBoostAfterDashing = 0.7
MaxNumberOfDashActions = 2
PerfectlyTimedActionTimer = 0.3
BasicDashStrength = 15.0
DashTimeDilationCurve = ExtResource("2_2q0ik")
@ -63,6 +65,7 @@ move = ExtResource("17_h6vvl")
rotate_y = ExtResource("4_rxwoh")
rotate_floorplane = ExtResource("5_4u7i3")
aim_down = ExtResource("8_obsfv")
aim_pressed = ExtResource("9_nob5r")
aim_released = ExtResource("8_lhb11")
empower_down = ExtResource("10_nodcl")
empower_released = ExtResource("11_ruloh")
@ -195,6 +198,10 @@ ignore_time_scale = true
wait_time = 0.3
one_shot = true
[node name="EmpowerTimeDownscale" type="Timer" parent="."]
one_shot = true
ignore_time_scale = true
[node name="StateChartDebugger" parent="." instance=ExtResource("24_q5h8a")]
offset_left = 1524.0
offset_top = 1.0
@ -262,6 +269,12 @@ script = ExtResource("27_infe6")
script = ExtResource("26_infe6")
initial_state = NodePath("Off")
[node name="ToOff" type="Node" parent="StateChart/Root/Aim"]
script = ExtResource("28_n7qhm")
to = NodePath("../Off")
event = &"aim_released"
delay_in_seconds = "0.0"
[node name="Off" type="Node" parent="StateChart/Root/Aim"]
script = ExtResource("27_34snm")
@ -274,12 +287,15 @@ delay_in_seconds = "0.0"
[node name="On" type="Node" parent="StateChart/Root/Aim"]
script = ExtResource("27_34snm")
[node name="ToOff" type="Node" parent="StateChart/Root/Aim/On"]
[node name="ToCancel" type="Node" parent="StateChart/Root/Aim/On"]
script = ExtResource("28_n7qhm")
to = NodePath("../../Off")
event = &"aim_released"
to = NodePath("../../Canceled")
event = &"cancel_aim"
delay_in_seconds = "0.0"
[node name="Canceled" type="Node" parent="StateChart/Root/Aim"]
script = ExtResource("27_34snm")
[node name="Empower" type="Node" parent="StateChart/Root"]
script = ExtResource("26_infe6")
initial_state = NodePath("Off")
@ -326,12 +342,36 @@ script = ExtResource("26_infe6")
initial_state = NodePath("InHand")
metadata/_custom_type_script = "uid://c1vp0ojjvaby1"
[node name="ToPlanted" type="Node" parent="StateChart/Root/WeaponState"]
script = ExtResource("28_n7qhm")
to = NodePath("../Planted")
event = &"plant_weapon"
delay_in_seconds = "0.0"
[node name="ToHand" type="Node" parent="StateChart/Root/WeaponState"]
script = ExtResource("28_n7qhm")
to = NodePath("../InHand")
event = &"recover_weapond"
delay_in_seconds = "0.0"
[node name="InHand" type="Node" parent="StateChart/Root/WeaponState"]
script = ExtResource("27_34snm")
[node name="ToThrown" type="Node" parent="StateChart/Root/WeaponState/InHand"]
script = ExtResource("28_n7qhm")
to = NodePath("../../Flying")
event = &"throw"
delay_in_seconds = "0.0"
[node name="Flying" type="Node" parent="StateChart/Root/WeaponState"]
script = ExtResource("27_34snm")
[node name="ToPlanted" type="Node" parent="StateChart/Root/WeaponState/Flying"]
script = ExtResource("28_n7qhm")
to = NodePath("../../Planted")
event = &"plant_weapon"
delay_in_seconds = "0.0"
[node name="Planted" type="Node" parent="StateChart/Root/WeaponState"]
script = ExtResource("27_34snm")
@ -517,6 +557,7 @@ delay_in_seconds = "0.0"
[connection signal="input_aim_canceled" from="InputController" to="." method="OnInputAimCanceled"]
[connection signal="input_aim_down" from="InputController" to="." method="OnInputAimDown"]
[connection signal="input_aim_pressed" from="InputController" to="." method="OnInputAimPressed"]
[connection signal="input_aim_released" from="InputController" to="." method="OnInputAimReleased"]
[connection signal="input_dash" from="InputController" to="." method="OnInputDashPressed"]
[connection signal="input_empower_down" from="InputController" to="." method="OnInputEmpowerDown"]

View File

@ -46,6 +46,7 @@ public partial class PlayerController : CharacterBody3D
private Timer _timeScaleAimInAirTimer;
private Timer _timeAfterDashingTimer;
private Timer _dashCooldownTimer;
private Timer _empowerTimeDownscale;
[Export(PropertyHint.Range, "0,1,0.01,or_greater")]
public float TimeScaleAimInAir { get; set; } = 0.2f;
@ -57,25 +58,27 @@ public partial class PlayerController : CharacterBody3D
[Export(PropertyHint.Range, "0,200,1,or_greater")]
public int DashIndicatorStartSize { get; set; } = 100;
[Export(PropertyHint.Range, "0,1,0.01")]
public float DashProgressAfterWhichToAct { get; set; } = 0.8f;
public float PerfectlyTimedActionTimer { get; set; } = 0.8f;
[Export(PropertyHint.Range, "0,50,0.1")]
public float BasicDashStrength { get; set; } = 10f;
[Export]
public Curve DashTimeDilationCurve { get; set; }
private bool _canDash = true;
private int _dashActionsLeft;
public int DashActionsLeft
private int _empoweredActionsLeft;
public int EmpoweredActionsLeft
{
get => _dashActionsLeft;
get => _empoweredActionsLeft;
set
{
_dashActionsLeft = value;
_empoweredActionsLeft = value;
PlayerUi.SetNumberOfDashesLeft(value);
}
}
private bool _isWallJumpAvailable = true;
private bool _isActionPerfectlyTimed = false;
private StateChart _playerState;
@ -176,6 +179,7 @@ public partial class PlayerController : CharacterBody3D
_dashCooldownTimer = GetNode<Timer>("DashCooldown");
_timeScaleAimInAirTimer = GetNode<Timer>("TimeScaleAimInAir");
_timeAfterDashingTimer = GetNode<Timer>("TimeAfterDashing");
_empowerTimeDownscale = GetNode<Timer>("EmpowerTimeDownscale");
///////////////////////////
// Initialize components //
@ -216,7 +220,7 @@ public partial class PlayerController : CharacterBody3D
HealthSystem.Init(healthSystemParams);
Stamina.SetSpeeds(MoveSystem.WalkSpeed, MoveSystem.SprintSpeed);
DashActionsLeft = MaxNumberOfDashActions;
EmpoweredActionsLeft = MaxNumberOfDashActions;
///////////////////////////
// Signal setup ///////////
@ -229,9 +233,8 @@ public partial class PlayerController : CharacterBody3D
_aiming.StateProcessing += HandleAiming;
_aiming.StateEntered += OnAimingEntered;
_aiming.StateExited += ResetTimeScale;
_aiming.StateExited += OnAimingExited;
/*_crouched.StatePhysicsProcessing += HandleGroundedCrouched;
_standing.StatePhysicsProcessing += HandleGroundedStanding;*/
_grounded.StateEntered += OnGrounded;
_grounded.StatePhysicsProcessing += HandleGrounded;
_airborne.StatePhysicsProcessing += HandleAirborne;
@ -242,7 +245,36 @@ public partial class PlayerController : CharacterBody3D
_timeScaleAimInAirTimer.Timeout += ResetTimeScale;
_dashing.StatePhysicsProcessing += Dashing;
_weaponThrown.StateEntered += OnWeaponThrown;
// _weaponThrown.StateEntered += OnWeaponThrown;
_empowerOn.StateEntered += OnEmpowerStarted;
_empowerOn.StateProcessing += HandleEmpower;
_empowerTimeDownscale.Timeout += EmpowerStopped;
}
public void OnEmpowerStarted()
{
_empowerTimeDownscale.Start();
_isActionPerfectlyTimed = true;
Engine.SetTimeScale(0.1f);
}
public void HandleEmpower(float delta)
{
var progress = (float) (_empowerTimeDownscale.TimeLeft / _empowerTimeDownscale.WaitTime);
_isActionPerfectlyTimed = progress < PerfectlyTimedActionTimer;
var indicatorColor = _isActionPerfectlyTimed ? Colors.Green : Colors.White;
DashIndicator.SetCustomMinimumSize(Vector2.One * DashIndicatorStartSize * progress);
DashIndicator.SetModulate(indicatorColor);
DashIndicator.Visible = true;
}
public void EmpowerStopped()
{
DashIndicator.Visible = false;
ResetTimeScale();
_isActionPerfectlyTimed = false;
}
///////////////////////////
@ -264,6 +296,10 @@ public partial class PlayerController : CharacterBody3D
public void OnInputAimPressed()
{
_playerState.SendEvent("aim_pressed");
if (!WeaponSystem.InHandState.Active)
{
OnDashStarted();
}
}
public void OnInputAimDown()
{
@ -280,7 +316,10 @@ public partial class PlayerController : CharacterBody3D
}
public void OnInputHitPressed()
{
_playerState.SendEvent("hit_pressed");
if (_aiming.Active)
{
OnWeaponThrown();
}
}
public void OnInputJumpPressed()
{
@ -290,15 +329,21 @@ public partial class PlayerController : CharacterBody3D
return;
}
if (_grounded.Active || _coyoteEnabled.Active)
if (_empowerOn.Active)
if (_empowerOn.Active && CanPerformEmpoweredAction())
{
PerformEmpoweredAction();
PerformJump(MoveSystem.JumpTypes.JumpFromDash);
}
else
Jump();
PerformJump(MoveSystem.JumpTypes.SimpleJump);
else if (_doubleJumpEnabled.Active)
if (_empowerOn.Active)
if (_empowerOn.Active && CanPerformEmpoweredAction())
{
PerformEmpoweredAction();
PerformJump(MoveSystem.JumpTypes.JumpFromDash);
}
else
DoubleJump();
PerformJump(MoveSystem.JumpTypes.DoubleJump);
else if (_onWall.Active)
JumpFromWall(_empowerOn.Active);
@ -312,7 +357,7 @@ public partial class PlayerController : CharacterBody3D
}
public void OnInputThrowPressed()
{
_playerState.SendEvent("throw");
}
public void OnInputEmpowerDown()
{
@ -325,9 +370,25 @@ public partial class PlayerController : CharacterBody3D
public void PerformDash(bool isEmpowered)
{
if (_aiming.Active)
{
OnDashStarted();
return;
}
if (!_canDash)
return;
_canDash = false;
var dashStrength = BasicDashStrength;
if (isEmpowered && CanPerformEmpoweredAction())
{
PerformEmpoweredAction();
dashStrength *= 2.5f;
}
var direction = HeadSystem.Transform.Basis * _inputMove;
var planarDirection = new Vector3(direction.X, 0, direction.Z).Normalized();
var dashStrength = isEmpowered ? BasicDashStrength * 2.5f : BasicDashStrength;
SetVelocity(planarDirection * dashStrength);
}
@ -344,20 +405,31 @@ public partial class PlayerController : CharacterBody3D
// Simple states
public void OnGrounded()
{
DashActionsLeft = MaxNumberOfDashActions;
RestoreEmpoweredActions();
}
private void RestoreEmpoweredActions()
{
EmpoweredActionsLeft = MaxNumberOfDashActions;
_isWallJumpAvailable = true;
}
public bool CanPerformEmpoweredAction()
{
return DashActionsLeft > 0 && _dashCooldownTimer.IsStopped();
return EmpoweredActionsLeft > 0;
}
public void PerformEmpoweredAction()
{
_isWallJumpAvailable = true;
_dashCooldownTimer.Start();
DashActionsLeft--;
if (!_isActionPerfectlyTimed)
{
EmpoweredActionsLeft--;
}
_empowerTimeDownscale.Stop();
EmpowerStopped();
}
// Jumping
@ -369,17 +441,6 @@ public partial class PlayerController : CharacterBody3D
{
_playerState.SendEvent("coyote_expired");
}
public void Jump()
{
if (_aiming.Active && CanPerformEmpoweredAction())
{
_playerState.SendEvent("jump_from_dash");
PerformEmpoweredAction();
PerformJump(MoveSystem.JumpTypes.JumpFromDash);
return;
}
PerformJump(MoveSystem.JumpTypes.SimpleJump);
}
public void JumpFromWall(bool isEmpowered)
{
if (!_isWallJumpAvailable)
@ -397,16 +458,6 @@ public partial class PlayerController : CharacterBody3D
}
PerformJump(MoveSystem.JumpTypes.JumpFromWall, jumpDirection);
}
public void DoubleJump()
{
if (_aiming.Active && CanPerformEmpoweredAction())
{
PerformEmpoweredAction();
PerformJump(MoveSystem.JumpTypes.JumpFromDash);
return;
}
PerformJump(MoveSystem.JumpTypes.DoubleJump);
}
private void PerformJump(MoveSystem.JumpTypes jumpType, Vector3? jumpDirection = null)
{
var effectiveJumpDirection = jumpDirection ?? Vector3.Up;
@ -478,10 +529,12 @@ public partial class PlayerController : CharacterBody3D
public void OnDashProgress(float progress)
{
return;
Engine.SetTimeScale(DashTimeDilationCurve.Sample(progress));
DashIndicator.SetCustomMinimumSize(Vector2.One * DashIndicatorStartSize * (1 - progress));
var indicatorColor = progress < DashProgressAfterWhichToAct ? new Color(1, 1, 1) : new Color(0, 1, 0);
var indicatorColor = progress < PerfectlyTimedActionTimer ? new Color(1, 1, 1) : new Color(0, 1, 0);
DashIndicator.SetModulate(indicatorColor);
}
public void OnDashEnded()
@ -522,15 +575,18 @@ 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()
{
DashSystem.CancelDash();
_playerState.SendEvent("cancel_aim");
RemoveChild(WeaponRoot);
GetTree().GetRoot().AddChild(WeaponRoot);
WeaponRoot.SetGlobalPosition(GlobalPosition);
DashSystem.CancelDash();
var weaponTargetLocation = DashSystem.HasHit ? DashSystem.CollisionPoint : DashSystem.TargetLocation;
WeaponSystem.ThrowWeapon(
weaponTargetLocation,
@ -540,32 +596,38 @@ public partial class PlayerController : CharacterBody3D
}
public void OnAimingEntered()
{
if (!WeaponSystem.InHandState.Active)
{
OnDashStarted();
return;
}
if (!isOnFloorCustom() && CanPerformEmpoweredAction())
ReduceTimeScaleWhileAiming();
}
public void OnAimingExited()
{
DashSystem.CancelDash();
}
// Regular processes
public void HandleWeaponInHand(float delta)
{
RotateWeaponWithPlayer();
if (WeaponSystem.InHandState.Active)
RotateWeaponWithPlayer();
}
public void HandleAiming(float delta)
{
RotateWeaponWithPlayer();
if (isOnFloorCustom())
ResetTimeScale();
if (CanPerformEmpoweredAction())
DashSystem.PrepareDash();
else
{
_playerState.SendEvent("aim_canceled");
DashSystem.CancelDash();
}
}
// Physics processes
public void HandleGrounded(float delta)
{
_canDash = true;
if (!isOnFloorCustom())
_playerState.SendEvent("start_falling");
}