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()