fixed dashing through terrain so easily when targeting enemy
This commit is contained in:
@@ -281,6 +281,7 @@ public partial class PlayerController : CharacterBody3D,
|
||||
private float _playerHeight;
|
||||
private float _playerRadius;
|
||||
private Vector3 _dashDirection = Vector3.Zero;
|
||||
private Vector3 _postDashThroughPosition = Vector3.Zero;
|
||||
private Vector3 _preDashVelocity = Vector3.Zero;
|
||||
private int _empoweredActionsLeft;
|
||||
public int EmpoweredActionsLeft
|
||||
@@ -2093,26 +2094,32 @@ public partial class PlayerController : CharacterBody3D,
|
||||
}
|
||||
|
||||
private PhysicsDirectSpaceState3D _spaceState;
|
||||
|
||||
public void StartDashAction(bool isParry)
|
||||
{
|
||||
var streamName = isParry ? "parry" : "attacks";
|
||||
_audioStream!.SwitchToClipByName(streamName);
|
||||
IsInvincible = true;
|
||||
|
||||
var plannedDashLocation = _targetLocation + Vector3.Down*HeadSystem.Position.Y;
|
||||
var query = PhysicsRayQueryParameters3D.Create(HeadSystem.GlobalPosition, plannedDashLocation, DashSystem.DashCast3D.CollisionMask);
|
||||
var result = _spaceState.IntersectRay(query);
|
||||
if (result.Count > 0)
|
||||
{
|
||||
plannedDashLocation = (Vector3) result["position"];
|
||||
}
|
||||
var plannedDashLocation = _targetLocation + Vector3.Down*_playerHeight/2;
|
||||
// var enemySurfaceQuery = PhysicsRayQueryParameters3D.Create(HeadSystem.GlobalPosition, plannedDashLocation, DashSystem.DashCast3D.CollisionMask);
|
||||
// var enemySurfaceResult = _spaceState.IntersectRay(enemySurfaceQuery);
|
||||
// if (enemySurfaceResult.Count > 0)
|
||||
// {
|
||||
// plannedDashLocation = (Vector3) enemySurfaceResult["position"];
|
||||
// }
|
||||
|
||||
var travel = plannedDashLocation - (GlobalPosition + Vector3.Up*_playerHeight/2);
|
||||
_preDashVelocity = Velocity;
|
||||
var travel = plannedDashLocation - GlobalPosition;
|
||||
_dashDirection = travel.Normalized();
|
||||
|
||||
var postDashLocation = plannedDashLocation + 0.5f*travel;
|
||||
var wallBehindQuery = PhysicsRayQueryParameters3D.Create(GlobalPosition + Vector3.Up*HeadSystem.Position.Y, postDashLocation, GroundDetector.CollisionMask);
|
||||
var wallBehindResult = _spaceState.IntersectRay(wallBehindQuery);
|
||||
var shouldRebound = wallBehindResult.Count > 0;
|
||||
if (!shouldRebound) _postDashThroughPosition = postDashLocation;
|
||||
|
||||
var dashTween = CreatePositionTween(plannedDashLocation, AimedDashTime);
|
||||
if (isParry) dashTween.Finished += OnDashParryEnded;
|
||||
if (isParry || shouldRebound) dashTween.Finished += OnDashParryEnded;
|
||||
else dashTween.Finished += OnDashAttackEnded;
|
||||
}
|
||||
public void OnDashAttackStarted()
|
||||
@@ -2142,7 +2149,7 @@ public partial class PlayerController : CharacterBody3D,
|
||||
public void OnDashAttackEnded()
|
||||
{
|
||||
StopDashAction();
|
||||
GlobalPosition = ComputePositionAfterTargetedDash(_targetLocation, _targetHitLocation);
|
||||
GlobalPosition = _postDashThroughPosition;
|
||||
var postDashVelocity = _preDashVelocity.Length() > PostDashSpeed ? _preDashVelocity.Length() : PostDashSpeed;
|
||||
Velocity = _dashDirection * postDashVelocity;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user