least worst version

This commit is contained in:
2025-09-11 16:36:27 +02:00
parent 00c4c1ddfa
commit 285365becf
4 changed files with 193 additions and 158 deletions

View File

@ -4,7 +4,7 @@ namespace Movementtests.systems;
public partial class DashSystem: Node3D
{
public record DashLocation(bool HasHit, Vector3 TargetLocation);
public record DashLocation(bool HasHit, Vector3 TargetLocation, Vector3 CollisionPoint, Vector3 CollisionNormal);
[Export(PropertyHint.Range, "0,0.2,0.01,or_greater")]
@ -16,7 +16,7 @@ public partial class DashSystem: Node3D
public Vector3 TargetLocation { get; set; }
public Vector3 CollisionPoint { get; set; }
public Vector3 CollisionNormal { get; set; }
public Vector3 PlannedPlayerLocation { get; set; }
public Vector3 PlannedLocation { get; set; }
public bool ShouldMantle { get; set; }
public Vector3 PlannedMantleLocation { get; set; }
@ -45,10 +45,21 @@ public partial class DashSystem: Node3D
private Vector3 _globalDashPosition = Vector3.Zero;
private float _playerHeight;
private float _playerRadius;
public float DashCastRadius { get; set; }
public void Init(Node3D head, Camera3D camera, TweenQueueSystem tweenQueueSystem)
{
_dashCast3D = GetNode<ShapeCast3D>("DashCast3D");
var dashShape = _dashCast3D.GetShape() as SphereShape3D;
DashCastRadius = dashShape!.Radius;
_playerCast3D = GetNode<ShapeCast3D>("PlayerShapeCast3D");
var playerShape = _playerCast3D.GetShape() as CapsuleShape3D;
_playerHeight = playerShape!.Height;
_playerRadius = playerShape!.Radius;
_head = head;
_camera = camera;
@ -63,121 +74,90 @@ public partial class DashSystem: Node3D
_dashIndicatorAnim = GetNode<AnimationPlayer>("DashIndicator/AnimationPlayer");
}
private Vector3 RecurseThroughCollisions(Vector3 previousCollisionPoint, Vector3 previousNormal, int recursionDepth)
{
if (recursionDepth == 0)
return previousCollisionPoint;
var startPoint = previousCollisionPoint + previousNormal*_playerHeight;
_playerCast3D.SetGlobalPosition(startPoint);
_playerCast3D.SetTargetPosition(-previousNormal*_playerRadius);
var hasHit = _playerCast3D.IsColliding();
if (!hasHit)
return previousCollisionPoint;
return RecurseThroughCollisions(
_playerCast3D.GetCollisionPoint(0),
_playerCast3D.GetCollisionNormal(0),
recursionDepth - 1);
}
private DashLocation ComputeDashLocation()
{
var targetLocation = _dashCast3D.ToGlobal(_dashCast3D.TargetPosition);
var hasHit = _dashCast3D.IsColliding();
if (!hasHit)
{
return new DashLocation(false, targetLocation);
return new DashLocation(false, targetLocation, Vector3.Zero, Vector3.Zero);
}
CollisionPoint = _dashCast3D.GetCollisionPoint(0);
CollisionNormal = _dashCast3D.GetCollisionNormal(0);
var collisionPoint = _dashCast3D.GetCollisionPoint(0);
var collisionNormal = _dashCast3D.GetCollisionNormal(0);
var fraction = _dashCast3D.GetClosestCollisionSafeFraction();
var globalSweepPath = TargetLocation - _dashCast3D.GlobalPosition;
var globalSweepPath = targetLocation - _dashCast3D.GlobalPosition;
var locationAlongPath = _dashCast3D.GlobalPosition + globalSweepPath * fraction;
return new DashLocation(true, locationAlongPath, collisionPoint, collisionNormal);
// Pushes the point down when dashing to under a platform so head doesn't clip
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);
var finalLocation = locationAlongPath
+ CollisionNormal
* maxPushDownDistance
* Mathf.Clamp(proportion, 0, 1)
* Mathf.Clamp(correctionProportion, 0, 1);
return new DashLocation(true, finalLocation);
}
public DashLocation GetDashLocationInDirection(Vector3 direction)
{
var angle = Mathf.Atan2(direction.X, direction.Z);
GD.Print(angle);
var rotation = _head.Rotation.Y + angle*2.0f;
_dashCast3D.SetRotation(new Vector3(0, rotation, 0));
return ComputeDashLocation();
// // Pushes the point down when dashing to under a platform so head doesn't clip
// 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);
// var finalLocation = locationAlongPath
// + CollisionNormal
// * maxPushDownDistance
// * Mathf.Clamp(proportion, 0, 1)
// * Mathf.Clamp(correctionProportion, 0, 1);
//
// return new DashLocation(true, finalLocation);
}
public void PrepareDash()
{
_dashTarget.SetVisible(false);
_dashCast3D.SetRotation(new Vector3(
_camera.Rotation.X,
_head.Rotation.Y,
_camera.Rotation.Z));
(HasHit, PlannedPlayerLocation) = ComputeDashLocation();
(HasHit, PlannedLocation, CollisionPoint, CollisionNormal) = ComputeDashLocation();
ShouldMantle = false;
var mantleLocation = Vector3.Zero;
if (HasHit && Mathf.Abs(CollisionNormal.Y) < 0.5f)
{
var mantleResult = _mantleSystem.FindMantleLocationAtPoint(PlannedPlayerLocation, CollisionNormal);
ShouldMantle = mantleResult.IsSome(out mantleLocation);
}
PlannedMantleLocation = mantleLocation;
// var mantleLocation = Vector3.Zero;
// if (HasHit && Mathf.Abs(CollisionNormal.Y) < 0.5f)
// {
// var mantleResult = _mantleSystem.FindMantleLocationAtPoint(PlannedLocation, CollisionNormal);
// ShouldMantle = mantleResult.IsSome(out mantleLocation);
// }
// PlannedMantleLocation = mantleLocation;
// Setup dash target
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(PlannedPlayerLocation);
_dashTarget.SetGlobalPosition(PlannedLocation);
}
public void CancelDash()
public void StopPreparingDash()
{
_dashTarget.SetVisible(false);
}
public void DashTweenEnded()
public void StartPreparingDash()
{
EmitSignal(SignalName.DashEnded);
_dashTarget.SetVisible(false);
}
public void Dash()
{
EmitSignal(SignalName.DashStarted);
var dashTweenInputs = new TweenQueueSystem.TweenInputs(PlannedPlayerLocation, DashSpeed);
var dashTween = _tweenQueueSystem.TweenToLocation(dashTweenInputs);
// dashTween.SetTrans(Tween.TransitionType.Cubic);
// dashTween.SetEase(Tween.EaseType.Out);
dashTween.TweenMethod(Callable.From<float>(Dashing), 0.0f, 1.0f, DashSpeed);
dashTween.Finished += DashTweenEnded;
if (ShouldMantle)
{
_tweenQueueSystem.QueueTween(PlannedMantleLocation, 0.2f);
return;
}
// var dashIndicator = (CpuParticles3D) DashIndicatorScene.Instantiate();
// GetTree().GetRoot().AddChild(dashIndicator);
// _globalDashPosition = _dashTarget.GlobalPosition + 1.5f*Vector3.Up;
// dashIndicator.GlobalPosition = _globalDashPosition;
// dashIndicator.SetEmitting(true);
}
public void Dashing(float proportion)
{
_dashTarget.SetGlobalPosition(_globalDashPosition);
EmitSignalDashProgress(proportion);
}
public void DashToThrownWeapon()
{
}
public void DashToPlantedWeapon()
{
_dashTarget.SetVisible(true);
}
}

View File

@ -16,13 +16,14 @@ script = ExtResource("1_hwig2")
DashIndicatorScene = ExtResource("2_tqt6i")
[node name="PlayerShapeCast3D" type="ShapeCast3D" parent="."]
visible = false
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, 0.85, 0)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.6, 0)
shape = SubResource("SphereShape3D_jngg2")
target_position = Vector3(0, 0, -12)
max_results = 1