mantle system fix amazing
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 22s
Create tag and build when new code gets to main / Export (push) Successful in 8m19s

This commit is contained in:
2025-12-19 18:59:34 +01:00
parent 2e2df4ff50
commit b792e8721c
8 changed files with 156 additions and 76 deletions

View File

@@ -1,8 +1,7 @@
[gd_scene load_steps=41 format=3 uid="uid://dmkw8cmalm5k"] [gd_scene load_steps=40 format=3 uid="uid://dmkw8cmalm5k"]
[ext_resource type="PackedScene" uid="uid://bei4nhkf8lwdo" path="res://player_controller/PlayerController.tscn" id="1_2vsi6"] [ext_resource type="PackedScene" uid="uid://bei4nhkf8lwdo" path="res://player_controller/PlayerController.tscn" id="1_2vsi6"]
[ext_resource type="Script" uid="uid://blenis2y55fmg" path="res://tools/city_helpers.gd" id="1_qwuk2"] [ext_resource type="Script" uid="uid://blenis2y55fmg" path="res://tools/city_helpers.gd" id="1_qwuk2"]
[ext_resource type="Resource" uid="uid://bl5crtu1gkrtr" path="res://systems/inputs/base_mode/base_mode.tres" id="2_p287n"]
[ext_resource type="Texture2D" uid="uid://ca4kkq3w8cd4n" path="res://assets/sky/sky_15_2k.png" id="2_ruo5i"] [ext_resource type="Texture2D" uid="uid://ca4kkq3w8cd4n" path="res://assets/sky/sky_15_2k.png" id="2_ruo5i"]
[ext_resource type="PackedScene" uid="uid://dkr80d2pi0d41" path="res://addons/guide/debugger/guide_debugger.tscn" id="2_uet8a"] [ext_resource type="PackedScene" uid="uid://dkr80d2pi0d41" path="res://addons/guide/debugger/guide_debugger.tscn" id="2_uet8a"]
[ext_resource type="Script" uid="uid://cyh0d64pfygbl" path="res://addons/maaacks_game_template/base/scripts/pause_menu_controller.gd" id="7_ukfuy"] [ext_resource type="Script" uid="uid://cyh0d64pfygbl" path="res://addons/maaacks_game_template/base/scripts/pause_menu_controller.gd" id="7_ukfuy"]
@@ -92,7 +91,6 @@ adjustment_enabled = true
[node name="Main" type="Node3D"] [node name="Main" type="Node3D"]
script = ExtResource("1_qwuk2") script = ExtResource("1_qwuk2")
base_mode = ExtResource("2_p287n")
[node name="BackgroundMusicPlayer" parent="." instance=ExtResource("9_i2xii")] [node name="BackgroundMusicPlayer" parent="." instance=ExtResource("9_i2xii")]
stream = ExtResource("10_eca4n") stream = ExtResource("10_eca4n")
@@ -141,6 +139,7 @@ theme_override_constants/margin_bottom = 10
[node name="TutoMoveAndLook" type="VBoxContainer" parent="TutorialController/PanelContainer/MarginContainer"] [node name="TutoMoveAndLook" type="VBoxContainer" parent="TutorialController/PanelContainer/MarginContainer"]
unique_name_in_owner = true unique_name_in_owner = true
visible = false
layout_mode = 2 layout_mode = 2
theme_override_constants/separation = 0 theme_override_constants/separation = 0
@@ -376,9 +375,10 @@ shadow_opacity = 0.95
shadow_blur = 2.435 shadow_blur = 2.435
[node name="Player" parent="." node_paths=PackedStringArray("TutorialWeaponTarget") instance=ExtResource("1_2vsi6")] [node name="Player" parent="." node_paths=PackedStringArray("TutorialWeaponTarget") instance=ExtResource("1_2vsi6")]
transform = Transform3D(0.054514527, 0, -0.9985129, 0, 1, 0, 0.9985129, 0, 0.054514527, 0, -132.75, 118) transform = Transform3D(0.054514527, 0, -0.9985129, 0, 1, 0, 0.9985129, 0, 0.054514527, -6, 75.5, -13.5)
collision_layer = 17 collision_layer = 17
TutorialWeaponTarget = NodePath("../PlacedTutorialWeapon/WeaponLocationTarget") TutorialWeaponTarget = NodePath("../PlacedTutorialWeapon/WeaponLocationTarget")
TutorialDone = true
AccelerationAir = 1.5 AccelerationAir = 1.5
[node name="DebugLayer" type="CanvasLayer" parent="."] [node name="DebugLayer" type="CanvasLayer" parent="."]

View File

@@ -65,7 +65,7 @@ WalkSpeed = 7.5
AccelerationAir = 2.0 AccelerationAir = 2.0
DecelerationAir = 0.1 DecelerationAir = 0.1
Weight = 5.0 Weight = 5.0
MantleTime = 0.3 MantleTime = 0.2
CoyoteTime = 0.3 CoyoteTime = 0.3
SimpleJumpStartVelocity = 8.0 SimpleJumpStartVelocity = 8.0
SimpleJumpHangTimeInFrames = 1 SimpleJumpHangTimeInFrames = 1
@@ -502,45 +502,45 @@ delay_in_seconds = "0.0"
script = ExtResource("26_infe6") script = ExtResource("26_infe6")
initial_state = NodePath("SimpleJump") initial_state = NodePath("SimpleJump")
[node name="OnMantle" type="Node" parent="StateChart/Root/Movement/Jump"]
script = ExtResource("28_n7qhm")
to = NodePath("../../Mantling")
event = &"mantle"
delay_in_seconds = "0.0"
[node name="SimpleJump" type="Node" parent="StateChart/Root/Movement/Jump"] [node name="SimpleJump" type="Node" parent="StateChart/Root/Movement/Jump"]
script = ExtResource("27_34snm") script = ExtResource("27_34snm")
[node name="OnMegajump" type="Node" parent="StateChart/Root/Movement/Jump/SimpleJump"]
script = ExtResource("28_n7qhm")
to = NodePath("../../MegaJump")
event = &"megajump"
delay_in_seconds = "0.0"
[node name="OnJumpEnded" type="Node" parent="StateChart/Root/Movement/Jump/SimpleJump"] [node name="OnJumpEnded" type="Node" parent="StateChart/Root/Movement/Jump/SimpleJump"]
script = ExtResource("28_n7qhm") script = ExtResource("28_n7qhm")
to = NodePath("../../../Airborne/DoubleJumpEnabled") to = NodePath("../../../Airborne/DoubleJumpEnabled")
event = &"jump_ended" event = &"jump_ended"
delay_in_seconds = "0.0" delay_in_seconds = "0.0"
[node name="DoubleJump" type="Node" parent="StateChart/Root/Movement/Jump"] [node name="OnMegajump" type="Node" parent="StateChart/Root/Movement/Jump/SimpleJump"]
script = ExtResource("27_34snm")
[node name="OnMegajump" type="Node" parent="StateChart/Root/Movement/Jump/DoubleJump"]
script = ExtResource("28_n7qhm") script = ExtResource("28_n7qhm")
to = NodePath("../../MegaJump") to = NodePath("../../MegaJump")
event = &"megajump" event = &"megajump"
delay_in_seconds = "0.0" delay_in_seconds = "0.0"
[node name="DoubleJump" type="Node" parent="StateChart/Root/Movement/Jump"]
script = ExtResource("27_34snm")
[node name="OnJumpEnded" type="Node" parent="StateChart/Root/Movement/Jump/DoubleJump"] [node name="OnJumpEnded" type="Node" parent="StateChart/Root/Movement/Jump/DoubleJump"]
script = ExtResource("28_n7qhm") script = ExtResource("28_n7qhm")
to = NodePath("../../../Airborne/Falling") to = NodePath("../../../Airborne/Falling")
event = &"jump_ended" event = &"jump_ended"
delay_in_seconds = "0.0" delay_in_seconds = "0.0"
[node name="OnMegajump" type="Node" parent="StateChart/Root/Movement/Jump/DoubleJump"]
script = ExtResource("28_n7qhm")
to = NodePath("../../MegaJump")
event = &"megajump"
delay_in_seconds = "0.0"
[node name="MegaJump" type="Node" parent="StateChart/Root/Movement/Jump"] [node name="MegaJump" type="Node" parent="StateChart/Root/Movement/Jump"]
script = ExtResource("27_34snm") script = ExtResource("27_34snm")
[node name="OnJumpEnded" type="Node" parent="StateChart/Root/Movement/Jump/MegaJump"]
script = ExtResource("28_n7qhm")
to = NodePath("../../../Airborne/Falling")
event = &"jump_ended"
delay_in_seconds = "0.0"
[node name="Dashing" type="Node" parent="StateChart/Root/Movement"] [node name="Dashing" type="Node" parent="StateChart/Root/Movement"]
script = ExtResource("26_infe6") script = ExtResource("26_infe6")
initial_state = NodePath("Dash") initial_state = NodePath("Dash")
@@ -707,6 +707,12 @@ to = NodePath("../../Airborne/Reset")
event = &"start_falling" event = &"start_falling"
delay_in_seconds = "0.0" delay_in_seconds = "0.0"
[node name="OnMantle" type="Node" parent="StateChart/Root/Movement/OnWall"]
script = ExtResource("28_n7qhm")
to = NodePath("../../Mantling")
event = &"mantle"
delay_in_seconds = "0.0"
[node name="HuggingCoyoteEnabled" type="Node" parent="StateChart/Root/Movement/OnWall"] [node name="HuggingCoyoteEnabled" type="Node" parent="StateChart/Root/Movement/OnWall"]
script = ExtResource("27_34snm") script = ExtResource("27_34snm")

View File

@@ -81,6 +81,8 @@ public partial class PlayerController : CharacterBody3D
[ExportGroup("Mantle")] [ExportGroup("Mantle")]
[Export(PropertyHint.Range, "0,1,0.01,or_greater")] [Export(PropertyHint.Range, "0,1,0.01,or_greater")]
public float MantleTime { get; set; } = 0.1f; public float MantleTime { get; set; } = 0.1f;
[Export]
public PackedScene MantlePath { get; set; } = GD.Load<PackedScene>("res://scenes/path/Path.tscn");
// Jump // Jump
[ExportGroup("Jump")] [ExportGroup("Jump")]
@@ -186,6 +188,11 @@ public partial class PlayerController : CharacterBody3D
private bool _canDash = true; private bool _canDash = true;
private bool _shouldMantleOnDashEnded; private bool _shouldMantleOnDashEnded;
private Vector3 _wallHugStartLocation = Vector3.Zero;
private Vector3 _wallHugStartNormal = Vector3.Zero;
private Vector3 _wallHugStartProjectedVelocity = Vector3.Zero;
private Vector3 _currentWallContactPoint = Vector3.Zero;
private StateChart _playerState; private StateChart _playerState;
private StateChartState _aiming; private StateChartState _aiming;
@@ -197,7 +204,7 @@ public partial class PlayerController : CharacterBody3D
private StateChartState _grounded; private StateChartState _grounded;
private StateChartState _airborne; private StateChartState _airborne;
private StateChartState _coyoteEnabled; private StateChartState _coyoteEnabled;
private StateChartState _doubleJumpEnabled; // private StateChartState _doubleJumpEnabled;
private StateChartState _simpleJump; private StateChartState _simpleJump;
private StateChartState _doubleJump; private StateChartState _doubleJump;
private StateChartState _megaJump; private StateChartState _megaJump;
@@ -221,6 +228,7 @@ public partial class PlayerController : CharacterBody3D
private float _playerHeight; private float _playerHeight;
private float _playerRadius; private float _playerRadius;
private bool _isJumpInputPressed = false;
private float _lookSensitivityMultiplier = 1.0f; private float _lookSensitivityMultiplier = 1.0f;
private float _mouseSensitivityMultiplier = 1.0f; private float _mouseSensitivityMultiplier = 1.0f;
@@ -294,7 +302,7 @@ public partial class PlayerController : CharacterBody3D
_grounded = StateChartState.Of(GetNode("StateChart/Root/Movement/Grounded")); _grounded = StateChartState.Of(GetNode("StateChart/Root/Movement/Grounded"));
_airborne = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne")); _airborne = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne"));
_coyoteEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/CoyoteEnabled")); _coyoteEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/CoyoteEnabled"));
_doubleJumpEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/DoubleJumpEnabled")); // _doubleJumpEnabled = StateChartState.Of(GetNode("StateChart/Root/Movement/Airborne/DoubleJumpEnabled"));
_simpleJump = StateChartState.Of(GetNode("StateChart/Root/Movement/Jump/SimpleJump")); _simpleJump = StateChartState.Of(GetNode("StateChart/Root/Movement/Jump/SimpleJump"));
_doubleJump = StateChartState.Of(GetNode("StateChart/Root/Movement/Jump/DoubleJump")); _doubleJump = StateChartState.Of(GetNode("StateChart/Root/Movement/Jump/DoubleJump"));
_megaJump = StateChartState.Of(GetNode("StateChart/Root/Movement/Jump/MegaJump")); _megaJump = StateChartState.Of(GetNode("StateChart/Root/Movement/Jump/MegaJump"));
@@ -351,6 +359,7 @@ public partial class PlayerController : CharacterBody3D
_grounded.StateEntered += OnGrounded; _grounded.StateEntered += OnGrounded;
_grounded.StatePhysicsProcessing += HandleGrounded; _grounded.StatePhysicsProcessing += HandleGrounded;
_airborne.StatePhysicsProcessing += HandleAirborne; _airborne.StatePhysicsProcessing += HandleAirborne;
_onWall.StatePhysicsProcessing += HandleOnWall;
_coyoteEnabled.StateEntered += StartCoyoteTime; _coyoteEnabled.StateEntered += StartCoyoteTime;
_timeScaleAimInAirTimer.Timeout += ResetTimeScale; _timeScaleAimInAirTimer.Timeout += ResetTimeScale;
@@ -454,20 +463,29 @@ public partial class PlayerController : CharacterBody3D
{ {
_canDash = true; _canDash = true;
} }
public bool IsTryingToMantle()
{
return MantleSystem.IsMantlePossible && GetMoveInput().Z < -0.5f && _isJumpInputPressed;
}
public void HandleGrounded(float delta) public void HandleGrounded(float delta)
{ {
MoveOnGround(delta); MoveOnGround(delta);
// if (IsTryingToMantle()) _playerState.SendEvent("mantle");
if (!isOnFloorCustom()) if (!isOnFloorCustom())
_playerState.SendEvent("start_falling"); _playerState.SendEvent("start_falling");
} }
public void HandleAirborne(float delta) public void HandleAirborne(float delta)
{ {
MoveInAir(delta); MoveInAir(delta);
if (isOnFloorCustom()) if (isOnFloorCustom())
_playerState.SendEvent("grounded"); _playerState.SendEvent("grounded");
if (IsTryingToMantle()) _playerState.SendEvent("mantle");
if (!WallHugSystem.IsWallHugging()) if (!WallHugSystem.IsWallHugging())
return; return;
@@ -497,6 +515,11 @@ public partial class PlayerController : CharacterBody3D
} }
} }
public void HandleOnWall(float delta)
{
if (IsTryingToMantle()) _playerState.SendEvent("mantle");
}
public void OnWallHuggingStarted() public void OnWallHuggingStarted()
{ {
GetTree().CreateTimer(CoyoteTime).Timeout += CoyoteExpired; GetTree().CreateTimer(CoyoteTime).Timeout += CoyoteExpired;
@@ -507,11 +530,6 @@ public partial class PlayerController : CharacterBody3D
GetTree().CreateTimer(CoyoteTime).Timeout += CoyoteExpired; GetTree().CreateTimer(CoyoteTime).Timeout += CoyoteExpired;
} }
private Vector3 _wallHugStartLocation = Vector3.Zero;
private Vector3 _wallHugStartNormal = Vector3.Zero;
private Vector3 _wallHugStartProjectedVelocity = Vector3.Zero;
private Vector3 _currentWallContactPoint = Vector3.Zero;
public void OnWallDetected() public void OnWallDetected()
{ {
FinishPoweredDash(); FinishPoweredDash();
@@ -591,10 +609,11 @@ public partial class PlayerController : CharacterBody3D
Velocity = Vector3.Zero; Velocity = Vector3.Zero;
GlobalPosition = _wallHugStartLocation; GlobalPosition = _wallHugStartLocation;
} }
// Jump // Jump
public void OnInputJumpStarted() public void OnInputJumpStarted()
{ {
_isJumpInputPressed = true;
if (MantleSystem.IsMantlePossible) if (MantleSystem.IsMantlePossible)
{ {
_playerState.SendEvent("mantle"); _playerState.SendEvent("mantle");
@@ -620,6 +639,7 @@ public partial class PlayerController : CharacterBody3D
public void OnInputJumpEnded() public void OnInputJumpEnded()
{ {
_isJumpInputPressed = false;
_playerState.SendEvent("jump_ended"); _playerState.SendEvent("jump_ended");
} }
@@ -725,38 +745,48 @@ public partial class PlayerController : CharacterBody3D
z: velocity.Y); z: velocity.Y);
} }
private Path _mantlePath;
public void OnMantleStarted() public void OnMantleStarted()
{ {
HeadSystem.OnMantle(); HeadSystem.OnMantle();
_mantlePath = MantlePath.Instantiate() as Path;
if (_mantlePath == null)
{
GD.PrintErr("Failed to instantiate MantlePath");
return;
};
_preMantleVelocity = Velocity; GetTree().GetRoot().AddChild(_mantlePath);
_mantlePath.Setup(MantleSystem.GlobalTransform, MantleSystem.MantleCurve);
var tween = GetTree().CreateTween(); var tween = GetTree().CreateTween();
tween.SetTrans(Tween.TransitionType.Cubic); tween.SetTrans(Tween.TransitionType.Linear);
tween.SetEase(Tween.EaseType.InOut); tween.SetEase(Tween.EaseType.InOut);
var inbetweenDuration = MantleTime / MantleSystem.NumberOfValidPofiles; tween.TweenProperty(_mantlePath.PathFollow, "progress_ratio", 1, MantleTime);
for (int i = 0; i < MantleSystem.NumberOfValidPofiles; i += 1)
{
var position = MantleSystem.WallProfilePositions[i];
tween.TweenProperty(this, "global_position", position, inbetweenDuration);
}
tween.Finished += MantleFinished; tween.Finished += MantleFinished;
} }
public void HandleMantling(float delta) public void HandleMantling(float delta)
{ {
GlobalPosition = _mantlePath.Target.GlobalPosition;
} }
public void MantleFinished() public void MantleFinished()
{ {
Velocity = _preMantleVelocity; _mantlePath.Teardown();
var direction = GetInputGlobalHDirection();
if (direction.Length() > 0)
{
SetVelocity(direction * SimpleDashStrength);
}
_playerState.SendEvent("grounded"); _playerState.SendEvent("grounded");
} }
public void HandleJump(float delta, float gravityFactor, int hangFrames) public void HandleJump(float delta, float gravityFactor, int hangFrames)
{ {
if (IsTryingToMantle()) _playerState.SendEvent("mantle");
// Update horizontal velocity // Update horizontal velocity
var horizontalVelocity = ComputeHVelocityAir(delta); var horizontalVelocity = ComputeHVelocityAir(delta);
Velocity = new Vector3(horizontalVelocity.X, Velocity.Y, horizontalVelocity.Z); Velocity = new Vector3(horizontalVelocity.X, Velocity.Y, horizontalVelocity.Z);
@@ -986,9 +1016,7 @@ public partial class PlayerController : CharacterBody3D
public void RecoverWeapon() public void RecoverWeapon()
{ {
GetTree().GetRoot().RemoveChild(WeaponRoot); RecoverChildNode(WeaponRoot);
AddChild(WeaponRoot);
WeaponRoot.SetGlobalPosition(GlobalPosition);
WeaponSystem.ResetWeapon(); WeaponSystem.ResetWeapon();
} }
@@ -1051,14 +1079,25 @@ public partial class PlayerController : CharacterBody3D
WeaponRoot.CallDeferred(Node3D.MethodName.SetGlobalPosition, TutorialWeaponTarget.GlobalPosition); WeaponRoot.CallDeferred(Node3D.MethodName.SetGlobalPosition, TutorialWeaponTarget.GlobalPosition);
WeaponSystem.CallDeferred(WeaponSystem.MethodName.PlaceWeaponForTutorial, TutorialWeaponTarget.GlobalPosition); WeaponSystem.CallDeferred(WeaponSystem.MethodName.PlaceWeaponForTutorial, TutorialWeaponTarget.GlobalPosition);
} }
public void RemoveChildNode(Node3D node)
{
RemoveChild(node);
GetTree().GetRoot().AddChild(node);
node.SetGlobalPosition(GlobalPosition);
}
public void RecoverChildNode(Node3D node)
{
GetTree().GetRoot().RemoveChild(node);
AddChild(node);
node.SetGlobalPosition(GlobalPosition);
}
public void ThrowWeapon() public void ThrowWeapon()
{ {
_playerState.SendEvent("cancel_aim"); _playerState.SendEvent("cancel_aim");
RemoveChildNode(WeaponRoot);
RemoveChild(WeaponRoot);
GetTree().GetRoot().AddChild(WeaponRoot);
WeaponRoot.SetGlobalPosition(GlobalPosition);
var weaponTargetLocation = DashSystem.HasHit ? DashSystem.CollisionPoint : DashSystem.PlannedLocation; var weaponTargetLocation = DashSystem.HasHit ? DashSystem.CollisionPoint : DashSystem.PlannedLocation;
WeaponSystem.ThrowWeapon( WeaponSystem.ThrowWeapon(

25
scenes/path/Path.cs Normal file
View File

@@ -0,0 +1,25 @@
using Godot;
public partial class Path : Path3D
{
public PathFollow3D PathFollow { get; private set; }
public Marker3D Target { get; private set; }
public override void _Ready()
{
PathFollow = GetNode<PathFollow3D>("PathFollow");
Target = GetNode<Marker3D>("PathFollow/Target");
}
public void Setup(Transform3D globalTransform, Curve3D curve)
{
SetGlobalTransform(globalTransform);
SetCurve(curve);
PathFollow.ProgressRatio = 0;
}
public void Teardown()
{
QueueFree();
}
}

1
scenes/path/Path.cs.uid Normal file
View File

@@ -0,0 +1 @@
uid://djdr5bvfc8f0x

13
scenes/path/path.tscn Normal file
View File

@@ -0,0 +1,13 @@
[gd_scene load_steps=3 format=3 uid="uid://cf3rrgr1imvv4"]
[ext_resource type="Script" uid="uid://djdr5bvfc8f0x" path="res://scenes/path/Path.cs" id="1_kmlhi"]
[sub_resource type="Curve3D" id="Curve3D_u4rfr"]
[node name="Path" type="Path3D"]
curve = SubResource("Curve3D_u4rfr")
script = ExtResource("1_kmlhi")
[node name="PathFollow" type="PathFollow3D" parent="."]
[node name="Target" type="Marker3D" parent="PathFollow"]

View File

@@ -14,17 +14,15 @@ public partial class MantleSystem: Node3D
private ShapeCast3D _wallInFrontCast3D; private ShapeCast3D _wallInFrontCast3D;
private ShapeCast3D _mantleCast3D; private ShapeCast3D _mantleCast3D;
private ShapeCast3D _inAirWallDetect; private ShapeCast3D _inAirWallDetect;
private ShapeCast3D _groundedWallDetect; private ShapeCast3D _groundedWallDetect;
public Curve3D MantleCurve { get; private set; }
public bool IsMantlePossible { get; private set; } = false; public bool IsMantlePossible { get; private set; } = false;
public int NumberOfValidPofiles { get; private set; } = -1;
public const int WallProfileCastCount = 7; public const int WallProfileCastCount = 7;
private ShapeCast3D[] _wallProfileShapecasts = new ShapeCast3D[WallProfileCastCount]; private ShapeCast3D[] _wallProfileShapecasts = new ShapeCast3D[WallProfileCastCount];
public Vector3[] WallProfilePositions { get; private set; } = new Vector3[WallProfileCastCount];
public Vector3[] WallProfileNormals { get; private set; } = new Vector3[WallProfileCastCount];
public void Init() public void Init()
{ {
@@ -55,21 +53,15 @@ public partial class MantleSystem: Node3D
SetCastsEnabled(isColliding); SetCastsEnabled(isColliding);
// Reset state // Reset state
NumberOfValidPofiles = -1;
IsMantlePossible = false; IsMantlePossible = false;
if (!isColliding) if (!isColliding) return;
{
return;
}
// Check if collide with wall // Check if collide with wall
var collisionNormal = isGrounded ? _groundedWallDetect.GetCollisionNormal(0) : _inAirWallDetect.GetCollisionNormal(0); var collisionNormal = isGrounded ? _groundedWallDetect.GetCollisionNormal(0) : _inAirWallDetect.GetCollisionNormal(0);
if (collisionNormal.Y > 0.8f) if (collisionNormal.Y > 0.9f) return;
{
return; MantleCurve = new Curve3D();
} MantleCurve.AddPoint(Vector3.Zero);
NumberOfValidPofiles = 0;
var hasFirstProfileHit = false; var hasFirstProfileHit = false;
foreach (var wallProfileShapecast in _wallProfileShapecasts) foreach (var wallProfileShapecast in _wallProfileShapecasts)
{ {
@@ -81,9 +73,7 @@ public partial class MantleSystem: Node3D
// Got to the other side of the wall, we stop there // Got to the other side of the wall, we stop there
if (!wallProfileShapecast.IsColliding()) if (!wallProfileShapecast.IsColliding())
{ {
WallProfilePositions[NumberOfValidPofiles] = globalTargetPosition; MantleCurve.AddPoint(ToLocal(globalTargetPosition));
WallProfileNormals[NumberOfValidPofiles] = Vector3.Zero;
NumberOfValidPofiles += 1;
break; break;
} }
@@ -92,16 +82,16 @@ public partial class MantleSystem: Node3D
// Check if we collided parallel to a wall // Check if we collided parallel to a wall
var isCollisionSameAsTarget = globalTargetPosition.IsEqualApprox(profilePoint); var isCollisionSameAsTarget = globalTargetPosition.IsEqualApprox(profilePoint);
var isCollidingWithWall = profileNormal.Y < 0.9f; var isCollidingWithWall = profileNormal.Y < 0.1f;
if (isCollisionSameAsTarget || isCollidingWithWall) continue; if (isCollisionSameAsTarget || isCollidingWithWall) continue;
// We have a valid collision // We have a valid collision
WallProfilePositions[NumberOfValidPofiles] = profilePoint;
WallProfileNormals[NumberOfValidPofiles] = profileNormal;
hasFirstProfileHit = true; hasFirstProfileHit = true;
NumberOfValidPofiles += 1; MantleCurve.AddPoint(ToLocal(profilePoint));
} }
IsMantlePossible = NumberOfValidPofiles > 0; // Should always be true if (MantleCurve.PointCount == 1) return;
IsMantlePossible = true;
} }
public Option<Vector3> FindMantle() public Option<Vector3> FindMantle()

View File

@@ -1,7 +1,6 @@
[gd_scene load_steps=6 format=3 uid="uid://wq1okogkhc5l"] [gd_scene load_steps=7 format=3 uid="uid://wq1okogkhc5l"]
[ext_resource type="Script" uid="uid://bja6tis1vaysu" path="res://systems/mantle/MantleSystem.cs" id="1_2oobp"] [ext_resource type="Script" uid="uid://bja6tis1vaysu" path="res://systems/mantle/MantleSystem.cs" id="1_2oobp"]
[ext_resource type="Shape3D" uid="uid://dp2p8v7demb5j" path="res://systems/mantle/find_wall_shape.tres" id="2_i32qj"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_4coqe"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_4coqe"]
height = 1.7 height = 1.7
@@ -9,6 +8,13 @@ height = 1.7
[sub_resource type="SphereShape3D" id="SphereShape3D_2oobp"] [sub_resource type="SphereShape3D" id="SphereShape3D_2oobp"]
radius = 0.75 radius = 0.75
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2oobp"]
radius = 0.25
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_i32qj"]
radius = 0.25
height = 1.5
[sub_resource type="SphereShape3D" id="SphereShape3D_i32qj"] [sub_resource type="SphereShape3D" id="SphereShape3D_i32qj"]
radius = 0.125 radius = 0.125
@@ -35,14 +41,14 @@ collision_mask = 2
debug_shape_custom_color = Color(0.911631, 0.11884, 0.656218, 1) debug_shape_custom_color = Color(0.911631, 0.11884, 0.656218, 1)
[node name="InAirWallDetect" type="ShapeCast3D" parent="."] [node name="InAirWallDetect" type="ShapeCast3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.26, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.01, 0)
shape = ExtResource("2_i32qj") shape = SubResource("CapsuleShape3D_2oobp")
target_position = Vector3(0, 0, -2) target_position = Vector3(0, 0, -2)
collision_mask = 2 collision_mask = 2
[node name="GroundedWallDetect" type="ShapeCast3D" parent="."] [node name="GroundedWallDetect" type="ShapeCast3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.76, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.26, 0)
shape = ExtResource("2_i32qj") shape = SubResource("CapsuleShape3D_i32qj")
target_position = Vector3(0, 0, -2) target_position = Vector3(0, 0, -2)
collision_mask = 2 collision_mask = 2