This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

HERES MY CODE PLZ HELP ME :CRY:

extends KinematicBody2D

const SPEED = 400
const JUMP = -400
const GRAVITY = 20

const UP = Vector2(0, -1)
var motion = Vector2()

func physicsprocess(delta):
motion.y += GRAVITY

if Input.is_action_pressed("RIGHT"):
    $AnimatedSprite.flip_h = false
    $AnimatedSprite.play("WALK")
    motion.x = SPEED
elif Input.is_action_pressed("LEFT"):
    $AnimatedSprite.flip_h = true
    $AnimatedSprite.play("WALK")
    motion.x = -SPEED
else:
    motion.x = 0
    $AnimatedSprite.play("IDLE")

if is_on_floor():
    if Input.is_action_just_pressed("JUMP"):
        motion.y = JUMP
else: 
        $AnimatedSprite.play("JUMP")

motion = move_and_slide(motion, UP)
Godot version 3.0
in Engine by (12 points)

1 Answer

0 votes

Play() functions means AnimationPlayer starts the process of animation from frame 0 to frame last in time given by the animation length. Think what can happen if You call play() every frame in physics_process(). It will endlessly jitter in frame 0 of course !
Design your code in a way animation play() is called only once. Look at your code - You already did it with jumping motion - it happens just once. Player rises up when he is on floor and jump is pressed, than he falls. He doesn't jump endlessly above viewport. Use the same sollution to make your animation be played once

by (8,188 points)
Any example code or how to define it ?
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.