Added new animations
This commit is contained in:
@@ -78,16 +78,30 @@ public partial class PlayerPhysicsController : CharacterBody2D {
|
||||
public override void _Process(double delta) {
|
||||
var grounded = this.IsOnFloor();
|
||||
var absvel = new Vector2(Mathf.Abs(Velocity.X), Mathf.Abs(Velocity.Y));
|
||||
Sprite.FlipH = Velocity.X < 0;
|
||||
if (grounded && absvel.X > 0) {
|
||||
Sprite.Play("walk", absvel.X switch {
|
||||
var xAxis = Input.GetAxis("move_left", "move_right");
|
||||
Sprite.FlipH = xAxis < 0;
|
||||
if (grounded && absvel.X > 0.1) {
|
||||
Sprite.Animation = "walk";
|
||||
Sprite.SpeedScale = absvel.X switch {
|
||||
< 10 => 1,
|
||||
< 150 => 2,
|
||||
< 300 => 4,
|
||||
_ => 1
|
||||
});
|
||||
} else if (grounded && absvel.X < epsilon && absvel.Y < epsilon) {
|
||||
Sprite.Play("idle");
|
||||
};
|
||||
} else {
|
||||
Sprite.SpeedScale = 1;
|
||||
}
|
||||
|
||||
if (grounded && absvel.X < 0.1) {
|
||||
Sprite.Animation = "idle";
|
||||
}
|
||||
|
||||
if (!grounded && Velocity.Y > 0.1) {
|
||||
Sprite.Animation = "fall";
|
||||
}
|
||||
|
||||
if (!grounded && Velocity.Y < 0.1) {
|
||||
Sprite.Animation = "jump";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user