Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Gaerzuk |
extends KinematicBody2D
const UP = Vector2(0,-1)
const GRAVITY = 10
const MAXFALLSPEED = 250
const MAXSPEED = 500
const JUMPFORCE = 300
const ACCEL = 90
const STOP = 0
var motion = Vector2()
var facing_right = true
func _ready():
pass
func _physics_process(_delta):
motion.y += GRAVITY
if motion.x > 0:
$Sprite.scale.x = 1
if motion.x < 0:
$Sprite.scale.x = -1
motion.x = clamp(motion.x, -MAXSPEED, MAXSPEED)
if motion.y > 10:
$AnimationPlayer.play("Fall")
if motion.y == 0:
$AnimationPlayer.play("Idle")
if motion.x > 0:
$AnimationPlayer.play("Run")
if motion.x < 0 :
$AnimationPlayer.play("Run")
if Input.is_action_pressed("ui_left"):
motion.x -= ACCEL
elif Input.is_action_pressed("ui_right"):
motion.x += ACCEL
elif Input.is_action_just_released("ui_left"):
motion.x = 0
$AnimationPlayer.play("Idle")
elif Input.is_action_just_released("ui_right"):
motion.x = 0
$AnimationPlayer.play("Idle")
if is_on_floor():
if Input.is_action_pressed("ui_up"):
$AnimationPlayer.play("Jump")
motion.y = -JUMPFORCE
if facing_right == true:
if Input.is_action_just_pressed("ui_page_down"):
$AnimationPlayer.play("Attack2")
position.x += 200
$Sprite.scale.x = 1
if Input.is_action_just_pressed("ui_page_up"):
$AnimationPlayer.play("Attack2")
position.x -= 200
$Sprite.scale.x = -1
if Input.is_action_pressed("ui_accept"):
$AnimationPlayer.play("Attack1")
motion = move_and_slide(motion, UP)
have u tried getting the signal “animation_finnished” from the animationPlayer node?
if you havent maybe you can try this, but after connecting the signal from your animationPlayer:
func _on_animation_player_animation_finished(anim_name):
if anim_name == "Attack1" or anim_name == "Attack2":
$AnimationPlayer.play("Idle")
JustADeer | 2022-12-29 06:58
can u show me a very specific example?
Gaerzuk | 2022-12-30 21:37