The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes
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 physicsprocess(_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)
Godot version 3 I think
in Engine by (12 points)

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")

can u show me a very specific example?

1 Answer

0 votes

If you're trying to transition between multiple animations, usually my recommendation is to use animation_tree

by (26 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.