small refacto of dash actions
This commit is contained in:
@@ -61,7 +61,7 @@ metadata/_custom_type_script = "uid://jitubgv6judn"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_abfq8"]
|
||||
script = ExtResource("3_cb2lu")
|
||||
Modifier = 10.0
|
||||
Modifier = 20.0
|
||||
metadata/_custom_type_script = "uid://b44cse62qru7j"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_ue7xq"]
|
||||
|
||||
@@ -2043,14 +2043,14 @@ public partial class PlayerController : CharacterBody3D,
|
||||
|
||||
// TODO: fix repeated code and improve parry knockback
|
||||
private PhysicsDirectSpaceState3D _spaceState;
|
||||
public void OnDashAttackStarted()
|
||||
{
|
||||
_audioStream!.SwitchToClipByName("attacks");
|
||||
|
||||
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)
|
||||
@@ -2058,67 +2058,48 @@ public partial class PlayerController : CharacterBody3D,
|
||||
plannedDashLocation = (Vector3) result["position"];
|
||||
}
|
||||
|
||||
var travel = plannedDashLocation - GlobalPosition;
|
||||
var travel = plannedDashLocation - (GlobalPosition + Vector3.Up*_playerHeight);
|
||||
_preDashVelocity = Velocity;
|
||||
_dashDirection = travel.Normalized();
|
||||
var dashTween = CreatePositionTween(plannedDashLocation, AimedDashTime);
|
||||
dashTween.Finished += OnDashAttackEnded;
|
||||
if (isParry) dashTween.Finished += OnDashParryEnded;
|
||||
else dashTween.Finished += OnDashAttackEnded;
|
||||
}
|
||||
public void OnDashAttackStarted()
|
||||
{
|
||||
StartDashAction(isParry: false);
|
||||
}
|
||||
public void OnDashParryStarted()
|
||||
{
|
||||
_audioStream!.SwitchToClipByName("parry");
|
||||
StartDashAction(isParry: true);
|
||||
}
|
||||
|
||||
_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)
|
||||
public void StopDashAction()
|
||||
{
|
||||
if (_targetObject is IDamageable damageable)
|
||||
{
|
||||
plannedDashLocation = (Vector3) result["position"];
|
||||
_hitEnemies.Add(damageable);
|
||||
TriggerDamage();
|
||||
}
|
||||
|
||||
var travel = plannedDashLocation - GlobalPosition;
|
||||
_preDashVelocity = Velocity;
|
||||
_dashDirection = travel.Normalized();
|
||||
var dashTween = CreatePositionTween(plannedDashLocation, AimedDashTime);
|
||||
dashTween.Finished += OnDashParryEnded;
|
||||
if (_targetObject is IStunnable stunnable)
|
||||
{
|
||||
stunnable.Stun();
|
||||
}
|
||||
_isInvincible = false;
|
||||
_playerState.SendEvent("attack_finished");
|
||||
}
|
||||
|
||||
public void OnDashAttackEnded()
|
||||
{
|
||||
if (_targetObject is IDamageable damageable)
|
||||
{
|
||||
_hitEnemies.Add(damageable);
|
||||
TriggerDamage();
|
||||
}
|
||||
if (_targetObject is IStunnable stunnable)
|
||||
{
|
||||
stunnable.Stun();
|
||||
}
|
||||
|
||||
StopDashAction();
|
||||
GlobalPosition = ComputePositionAfterTargetedDash(_targetLocation, _targetHitLocation);
|
||||
var postDashVelocity = _preDashVelocity.Length() > PostDashSpeed ? _preDashVelocity.Length() : PostDashSpeed;
|
||||
Velocity = _dashDirection * postDashVelocity;
|
||||
_isInvincible = false;
|
||||
_playerState.SendEvent("attack_finished");
|
||||
}
|
||||
public void OnDashParryEnded()
|
||||
{
|
||||
if (_targetObject is IDamageable damageable)
|
||||
{
|
||||
_hitEnemies.Add(damageable);
|
||||
TriggerDamage();
|
||||
}
|
||||
if (_targetObject is IStunnable stunnable)
|
||||
{
|
||||
stunnable.Stun();
|
||||
}
|
||||
|
||||
StopDashAction();
|
||||
Velocity = -_dashDirection*RKnockback.Modifier;
|
||||
_isInvincible = false;
|
||||
_playerState.SendEvent("attack_finished");
|
||||
}
|
||||
|
||||
public static Vector3 ComputePositionAfterTargetedDash(Vector3 targetLocation, Vector3 targetHitLocation)
|
||||
@@ -2138,7 +2119,6 @@ public partial class PlayerController : CharacterBody3D,
|
||||
DashToFlyingWeapon();
|
||||
return;
|
||||
}
|
||||
|
||||
if (WeaponSystem.PlantedState.Active)
|
||||
{
|
||||
DashToPlantedWeapon();
|
||||
|
||||
Reference in New Issue
Block a user