gd,fix: player won't go through thin platforms from underneath, added a small cooldown to dash actions, remapped inputs a bit for gamefeel

This commit is contained in:
2025-06-20 11:55:19 +02:00
parent 826eaac10c
commit 3a761fd0bd
9 changed files with 151 additions and 48 deletions

View File

@ -15,6 +15,7 @@ public partial class DashSystem: Node3D
private Node3D _head;
private ShapeCast3D _dashCast3D;
private ShapeCast3D _playerCast3D;
private Camera3D _camera;
private TweenQueueSystem _tweenQueueSystem;
private Vector3 _dashDirection = Vector3.Zero;
@ -34,6 +35,8 @@ public partial class DashSystem: Node3D
public void Init(Node3D head, Camera3D camera, TweenQueueSystem tweenQueueSystem)
{
_dashCast3D = GetNode<ShapeCast3D>("DashCast3D");
_playerCast3D = GetNode<ShapeCast3D>("PlayerShapeCast3D");
_head = head;
_camera = camera;
_tweenQueueSystem = tweenQueueSystem;
@ -53,9 +56,37 @@ public partial class DashSystem: Node3D
}
var collisionPoint = _dashCast3D.GetCollisionPoint(0);
var collisionNormal = _dashCast3D.GetCollisionNormal(0);
var collisionShape = (SphereShape3D) _dashCast3D.GetShape();
var centerSphereLocation = collisionPoint + collisionNormal * 0.2f;
return new DashComputationRecord(true, centerSphereLocation, collisionPoint, collisionNormal);
// var playerEndLocation = ComputeDashLocationForPlayerShape(collisionPoint, collisionNormal);
var fraction = _dashCast3D.GetClosestCollisionSafeFraction();
var globalSweepPath = _dashCast3D.ToGlobal(_dashCast3D.TargetPosition) - _dashCast3D.GlobalPosition;
var locationAlongPath = _dashCast3D.GlobalPosition + globalSweepPath * fraction;
var maxPushDownDistance = 0.9f;
var correctionProportion = (float)Mathf.Remap(collisionNormal.Y, -0.5, -1, 0, 1);
var proportion = (float) Mathf.Remap(_dashCast3D.GlobalRotation.X, 0, 1.57, 0, 1);
locationAlongPath += collisionNormal * maxPushDownDistance * proportion * correctionProportion;
var otherLocation = ComputeDashLocationForPlayerShape(collisionPoint, collisionNormal);
return new DashComputationRecord(true, locationAlongPath, collisionPoint, collisionNormal);
}
public Vector3 ComputeDashLocationForPlayerShape(Vector3 location, Vector3? normal = null)
{
if (!normal.HasValue)
return location;
var castStartLocation = location + 2 * normal.Value;
var castEndLocation = -2 * normal.Value;
_playerCast3D.SetGlobalPosition(castStartLocation);
_playerCast3D.SetTargetPosition(castEndLocation);
if (!_playerCast3D.IsColliding())
return castEndLocation;
var fraction = _playerCast3D.GetClosestCollisionSafeFraction();
var locationAlongPath = castEndLocation * fraction;
return castStartLocation + locationAlongPath;
}
public void PrepareDash()

View File

@ -1,11 +1,9 @@
[gd_scene load_steps=6 format=3 uid="uid://cqduhd4opgwvm"]
[ext_resource type="Script" uid="uid://dwoppk8j5fxeg" path="res://systems/dash/DashSystem.cs" id="1_hwig2"]
[ext_resource type="Shape3D" uid="uid://keseacdcooot" path="res://player_controller/resources/PlayerShape.tres" id="2_jngg2"]
[ext_resource type="PackedScene" uid="uid://wq1okogkhc5l" path="res://systems/mantle/mantle_system.tscn" id="2_pff7b"]
[sub_resource type="SphereShape3D" id="SphereShape3D_qu4wy"]
radius = 0.2
[sub_resource type="SphereMesh" id="SphereMesh_qu4wy"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_v31n3"]
@ -13,9 +11,15 @@ radius = 0.2
[node name="DashSystem" type="Node3D"]
script = ExtResource("1_hwig2")
[node name="PlayerShapeCast3D" type="ShapeCast3D" parent="."]
shape = ExtResource("2_jngg2")
target_position = Vector3(0, 0, 0)
collision_mask = 2
debug_shape_custom_color = Color(0.863327, 0.636844, 0, 1)
[node name="DashCast3D" type="ShapeCast3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.68, 0)
shape = SubResource("SphereShape3D_qu4wy")
shape = ExtResource("2_jngg2")
target_position = Vector3(0, 0, -12)
max_results = 1
collision_mask = 2