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