Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Viaas |
extends KinematicBody2D
var movement = Vector2();
var up = Vector2(0, -1);
var SPEED = 250;
var AttackPoints = 2;
var isAttacking = false;
var GRAVITY = 30;
var JUMPFORCE = -900
var velocity = Vector2(0,0)
onready var animationPlayer = $AnimationPlayer
func _process(delta):
if Input.is_action_pressed("right") && isAttacking == false :
movement.x = SPEED;
$Sprite.flip_h = false;
$AnimationPlayer.play("Running")
elif Input.is_action_pressed("left") && isAttacking == false :
movement.x = -SPEED;
$Sprite.flip_h = true;
$AnimationPlayer.play("Running")
else:
movement.x = 0;
if isAttacking == false:
$AnimationPlayer.play("Idle");
velocity.y = velocity.y + GRAVITY
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMPFORCE
$AnimationPlayer.play("jump")
velocity = move_and_slide(velocity,Vector2.UP)
velocity.x = lerp(velocity.x,0,0.2)
if Input.is_action_just_pressed("a") && AttackPoints == 2:
$AttackResetTimer.start();
isAttacking = true;
$AnimationPlayer.play("Attack 1");
AttackPoints = AttackPoints - 1;
elif Input.is_action_just_pressed(“a”) && AttackPoints == 1:
$AttackResetTimer.start();
$AnimationPlayer.play(“Attack 2”);
isAttacking = true;
AttackPoints = AttackPoints - 1;
if Input.is_action_just_pressed("s") && AttackPoints == 2:
$AttackResetTimer.start();
isAttacking = true;
$AnimationPlayer.play("Attack 2");
AttackPoints = AttackPoints - 1;
elif Input.is_action_just_pressed("s") && AttackPoints == 1:
$AttackResetTimer.start();
$AnimationPlayer.play("attack 3");
isAttacking = true;
AttackPoints = AttackPoints - 1;
if Input.is_action_just_pressed("d") && AttackPoints == 2:
$AttackResetTimer.start();
isAttacking = true;
$AnimationPlayer.play("attack 5");
AttackPoints = AttackPoints - 1;
elif Input.is_action_just_pressed("d") && AttackPoints == 1:
$AttackResetTimer.start();
$AnimationPlayer.play("Attack 6");
isAttacking = true;
AttackPoints = AttackPoints - 1;
movement = move_and_slide(movement, up * delta);
func _on_AnimationPlayer_animation_finished(anim):
if anim == “Attack 1” || “Attack 2” || “Attack 3”|| “Attack 4” || “Attack 5”|| “Attack 6”:
isAttacking = false;
$AnimationPlayer.play(“Idle”)
func _on_AttackResetTimer_timeout():
AttackPoints = 2;
Could you format your code properly and specify the actual version of Godot you’re using?
exuin | 2021-02-22 16:22
Another suggestion, that may not solve this problem, but will improve your code in future: try to use a consistent format for your animation names: some have capital letters (Idle
) and some don’t (jump
) and I would always avoid having spaces in names when coding.
gioele | 2021-02-25 00:59