4 direction dash
This commit is contained in:
parent
26dc7d4f57
commit
8577de2c04
3 changed files with 22 additions and 16 deletions
|
|
@ -59,6 +59,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
|
||||
/// The direction the player is currently holding.
|
||||
/// This vectors components should always be -1/0/1.
|
||||
private Vector2 _currentRawDirection = Vector2.Zero;
|
||||
private Vector2 _currentDirection = Vector2.Zero;
|
||||
|
||||
public bool IsFacingRight { get; private set; } = true;
|
||||
|
|
@ -109,11 +110,12 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
|| @event.IsAction(ActionName.MoveUp)
|
||||
|| @event.IsAction(ActionName.MoveDown))
|
||||
{
|
||||
_currentDirection = To8DirectionVector(Input.GetVector(
|
||||
_currentRawDirection = Input.GetVector(
|
||||
ActionName.MoveLeft,
|
||||
ActionName.MoveRight,
|
||||
ActionName.MoveUp,
|
||||
ActionName.MoveDown));
|
||||
ActionName.MoveDown);
|
||||
_currentDirection = To8DirectionVector(_currentRawDirection);
|
||||
}
|
||||
|
||||
if (Action.TryFromEvent(@event, out var action))
|
||||
|
|
@ -206,16 +208,12 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
IsFacingRight = Mathf.Sign(GetWallNormal().X) > 0;
|
||||
}
|
||||
|
||||
Velocity = velocity;
|
||||
if (!PlatformIgnoreTimer.IsStopped())
|
||||
{
|
||||
CollisionMask = 0b1;
|
||||
}
|
||||
else
|
||||
{
|
||||
CollisionMask = 0b0100_0001;
|
||||
}
|
||||
|
||||
var collideWithPlatforms = PlatformIgnoreTimer.IsStopped();
|
||||
// layer 7 is platforms
|
||||
SetCollisionMaskValue(7, collideWithPlatforms);
|
||||
|
||||
Velocity = velocity;
|
||||
MoveAndSlide();
|
||||
|
||||
{
|
||||
|
|
@ -434,7 +432,7 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
DashCooldownTimer.Start();
|
||||
DashDirection = (_currentDirection.IsZeroApprox()
|
||||
? FacingVector
|
||||
: _currentDirection
|
||||
: To4DirectionVector(_currentRawDirection)
|
||||
).Normalized();
|
||||
DashHitbox.StartAttack();
|
||||
_playback.Travel("side_dash");
|
||||
|
|
@ -453,6 +451,14 @@ public sealed partial class Player : CharacterBody2D, IAttackable, IHitboxOwner,
|
|||
s;
|
||||
}
|
||||
|
||||
private static Vector2 To4DirectionVector(Vector2 input)
|
||||
{
|
||||
if (input.IsZeroApprox()) return Vector2.Zero;
|
||||
Vector2 a = input.Abs(), s = input.Sign();
|
||||
return
|
||||
a.Y < a.X ? new(s.X, 0) : new(0, s.Y);
|
||||
}
|
||||
|
||||
private void OnEnemyHit(Hitbox hitbox, Node2D enemy)
|
||||
{
|
||||
if (enemy is not IAttackable attackable) return;
|
||||
|
|
|
|||
|
|
@ -308,7 +308,6 @@ advance_mode = 2
|
|||
advance_expression = "not is_on_floor() or _currentDirection.x == 0.0"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_ebec5"]
|
||||
advance_expression = "_is_on_wall()"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_yllr7"]
|
||||
advance_mode = 2
|
||||
|
|
@ -332,7 +331,7 @@ states/front_kick/position = Vector2(612.5, 32.5)
|
|||
states/idle/node = SubResource("AnimationNodeAnimation_yw30f")
|
||||
states/idle/position = Vector2(428.5, 88.5)
|
||||
states/parry/node = SubResource("AnimationNodeAnimation_5f2sf")
|
||||
states/parry/position = Vector2(544.82965, 277.5)
|
||||
states/parry/position = Vector2(537.82965, 253.5)
|
||||
states/run/node = SubResource("AnimationNodeAnimation_g6k8r")
|
||||
states/run/position = Vector2(678.5, 215.5)
|
||||
states/side_dash/node = SubResource("AnimationNodeAnimation_244u8")
|
||||
|
|
@ -504,6 +503,7 @@ one_shot = true
|
|||
[node name="PlatformIgnoreTimer" type="Timer" parent="." unique_id=1912509940]
|
||||
unique_name_in_owner = true
|
||||
process_callback = 0
|
||||
wait_time = 0.1
|
||||
one_shot = true
|
||||
|
||||
[node name="ParryTimer" type="Timer" parent="." unique_id=279087565]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue