From 4f5ca49c76e16ee85fefc63f3a0328038edffcb1 Mon Sep 17 00:00:00 2001 From: Minimata Date: Fri, 20 Jun 2025 13:56:42 +0200 Subject: [PATCH] fix: fixed some dash issues, there's still some --- player_controller/Scripts/PlayerController.cs | 20 +++-- systems/dash/DashSystem.cs | 74 +++++++++---------- 2 files changed, 49 insertions(+), 45 deletions(-) diff --git a/player_controller/Scripts/PlayerController.cs b/player_controller/Scripts/PlayerController.cs index a33cc2e..b63962e 100644 --- a/player_controller/Scripts/PlayerController.cs +++ b/player_controller/Scripts/PlayerController.cs @@ -233,7 +233,6 @@ public partial class PlayerController : CharacterBody3D public void OnInputAimPressed() { - GD.Print("InputAimPressed"); _playerState.SendEvent("aim_pressed"); } public void OnInputAimDown() @@ -379,16 +378,18 @@ public partial class PlayerController : CharacterBody3D _timeAfterDashingTimer.Start(); if (WeaponSystem.FlyingState.Active) { - DashSystem.DashResolve = new DashResolveRecord(false, WeaponSystem.GlobalPosition, Vector3.Zero); + DashSystem.ShouldMantle = false; + DashSystem.PlannedPlayerLocation = WeaponSystem.GlobalPosition; } else if (WeaponSystem.PlantedState.Active) { + DashSystem.ShouldMantle = false; // Should we try to resolve with mantle? var dashLocation = DashSystem.ComputeDashLocationForPlayerShape(WeaponSystem.PlantLocation, WeaponSystem.PlantNormal); - DashSystem.DashResolve = new DashResolveRecord(false, dashLocation, Vector3.Zero); + DashSystem.PlannedPlayerLocation = dashLocation; } - _dashDirection = (DashSystem.DashResolve.DashLocation - GlobalPosition).Normalized(); + _dashDirection = (DashSystem.PlannedPlayerLocation - GlobalPosition).Normalized(); DashSystem.Dash(); } public void OnDashEnded() @@ -436,12 +437,15 @@ public partial class PlayerController : CharacterBody3D RemoveChild(WeaponRoot); GetTree().GetRoot().AddChild(WeaponRoot); WeaponRoot.SetGlobalPosition(GlobalPosition); - - var (hasHit, location, collisionPoint, collisionNormal) = DashSystem.DashComputation; - var (endWithMantle, dashLocation, mantleLocation) = DashSystem.DashResolve; DashSystem.CancelDash(); - WeaponSystem.ThrowWeapon(location, hasHit, collisionPoint, collisionNormal); + + var weaponTargetLocation = DashSystem.HasHit ? DashSystem.CollisionPoint : DashSystem.TargetLocation; + WeaponSystem.ThrowWeapon( + weaponTargetLocation, + DashSystem.HasHit, + DashSystem.CollisionPoint, + DashSystem.CollisionNormal); } public void OnAimingEntered() { diff --git a/systems/dash/DashSystem.cs b/systems/dash/DashSystem.cs index b59bd67..d7c580b 100644 --- a/systems/dash/DashSystem.cs +++ b/systems/dash/DashSystem.cs @@ -2,10 +2,6 @@ namespace Movementtests.systems; -public record DashComputationRecord(bool HasHit, Vector3 Location, Vector3 CollisionPoint, Vector3 CollisionNormal); - -public record DashResolveRecord(bool EndWithMantle, Vector3 DashLocation, Vector3 MantleLocation); - public partial class DashSystem: Node3D { [Export(PropertyHint.Range, "0,0.2,0.01,or_greater")] @@ -13,6 +9,15 @@ public partial class DashSystem: Node3D [Export(PropertyHint.Range, "0,1000,1,or_greater")] public float PostDashSpeed { get; set; } = 0f; + public bool HasHit { get; set; } + public Vector3 TargetLocation { get; set; } + public Vector3 CollisionPoint { get; set; } + public Vector3 CollisionNormal { get; set; } + public Vector3 PlannedPlayerLocation { get; set; } + + public bool ShouldMantle { get; set; } + public Vector3 PlannedMantleLocation { get; set; } + private Node3D _head; private ShapeCast3D _dashCast3D; private ShapeCast3D _playerCast3D; @@ -23,9 +28,6 @@ public partial class DashSystem: Node3D private MantleSystem _mantleSystem; private MeshInstance3D _dashTarget; - public DashResolveRecord DashResolve { get; set; } - public DashComputationRecord DashComputation { get; set; } - [Signal] public delegate void DashStartedEventHandler(); @@ -48,27 +50,27 @@ public partial class DashSystem: Node3D _dashTarget.SetVisible(false); } - private DashComputationRecord ComputeDashLocation() + private void ComputeDashLocation() { - if (!_dashCast3D.IsColliding()) + TargetLocation = _dashCast3D.ToGlobal(_dashCast3D.TargetPosition); + HasHit = _dashCast3D.IsColliding(); + if (!HasHit) { - return new DashComputationRecord(false, _dashCast3D.ToGlobal(_dashCast3D.TargetPosition), Vector3.Zero, Vector3.Zero); + PlannedPlayerLocation = TargetLocation; + return; } - var collisionPoint = _dashCast3D.GetCollisionPoint(0); - var collisionNormal = _dashCast3D.GetCollisionNormal(0); - // var playerEndLocation = ComputeDashLocationForPlayerShape(collisionPoint, collisionNormal); + + CollisionPoint = _dashCast3D.GetCollisionPoint(0); + CollisionNormal = _dashCast3D.GetCollisionNormal(0); var fraction = _dashCast3D.GetClosestCollisionSafeFraction(); - var globalSweepPath = _dashCast3D.ToGlobal(_dashCast3D.TargetPosition) - _dashCast3D.GlobalPosition; + var globalSweepPath = TargetLocation - _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 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); + PlannedPlayerLocation = locationAlongPath + CollisionNormal * maxPushDownDistance * proportion * correctionProportion; } public Vector3 ComputeDashLocationForPlayerShape(Vector3 location, Vector3? normal = null) @@ -98,26 +100,24 @@ public partial class DashSystem: Node3D _head.Rotation.Y, _camera.Rotation.Z)); - DashComputation = ComputeDashLocation(); - var (hasHit, location, collisionPoint, collisionNormal) = DashComputation; - - var shouldMantle = false; - var mantleLocation = Vector3.Zero; - if (hasHit && Mathf.Abs(collisionNormal.Y) < 0.5f) - { - var mantleResult = _mantleSystem.FindMantleLocationAtPoint(collisionPoint, collisionNormal); - shouldMantle = mantleResult.IsSome(out mantleLocation); - } + ComputeDashLocation(); - var targetColor = hasHit ? new Color(1f, 0.2f, 0.2f) : new Color(1f, 1f, 1f); - targetColor = shouldMantle ? new Color(0.2f, 0.2f, 1f) : targetColor; + ShouldMantle = false; + var mantleLocation = Vector3.Zero; + if (HasHit && Mathf.Abs(CollisionNormal.Y) < 0.5f) + { + var mantleResult = _mantleSystem.FindMantleLocationAtPoint(CollisionPoint, CollisionNormal); + ShouldMantle = mantleResult.IsSome(out mantleLocation); + } + PlannedMantleLocation = mantleLocation; + + var targetColor = HasHit ? new Color(1f, 0.2f, 0.2f) : new Color(1f, 1f, 1f); + targetColor = ShouldMantle ? new Color(0.2f, 0.2f, 1f) : targetColor; var targetMaterial = (StandardMaterial3D) _dashTarget.GetSurfaceOverrideMaterial(0); targetMaterial.SetAlbedo(targetColor); _dashTarget.SetVisible(true); - _dashTarget.SetGlobalPosition(location); - - DashResolve = new DashResolveRecord(shouldMantle, location, mantleLocation); + _dashTarget.SetGlobalPosition(PlannedPlayerLocation); } public void CancelDash() @@ -134,12 +134,12 @@ public partial class DashSystem: Node3D { EmitSignal(SignalName.DashStarted); _dashTarget.SetVisible(false); - var dashTweenInputs = new TweenQueueSystem.TweenInputs(DashResolve.DashLocation, 0.1f); + var dashTweenInputs = new TweenQueueSystem.TweenInputs(PlannedPlayerLocation, 0.1f); var dashTween = _tweenQueueSystem.TweenToLocation(dashTweenInputs); dashTween.Finished += DashTweenEnded; - if (DashResolve.EndWithMantle) + if (ShouldMantle) { - _tweenQueueSystem.QueueTween(DashResolve.MantleLocation, 0.2f); + _tweenQueueSystem.QueueTween(PlannedMantleLocation, 0.2f); } }