Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Andrew27 |
Hi,
I’m coding a platformer game in godot, and the walking animation of the character is broken. I added the line: print($Sprite.animation) to check if it’s running the proper animations, and I noticed that it changes animations every time.
Here is the code:
extends KinematicBody2D
var motion=Vector2()
const UP=Vector2(0,-1)
var moving
func _physics_process(delta):
moving=false
if (Input.is_action_pressed("ui_right") and is_on_floor()):
motion.x+=50
moving=true
$Sprite.flip_h=false
if (Input.is_action_pressed("ui_left") and is_on_floor()):
motion.x+=-50
moving=true
$Sprite.flip_h=true
if (is_on_floor()):
friction()
motion.y+=9.80665
if (is_on_floor()):
if (Input.is_action_just_pressed("ui_up")):
motion.y=-400
else:
motion.y=0
if (is_on_wall()):
motion.x=0
animations()
move_and_slide(motion, UP)
func friction():
var direction
if (motion.x<0):
direction="left"
elif (motion.x>0):
direction="right"
else:
direction="NOTHING TO SEE HERE"
if (direction=="left"):
motion.x+=40
if (motion.x>0): motion.x=0
if (direction=="right"):
motion.x-=40
if (motion.x<0): motion.x=0
func animations():
if (motion.y>0 and not is_on_floor()):
$Sprite.play("Fall")
elif (motion.y<0):
$Sprite.play("Jump")
elif (moving):
$Sprite.play("Walk")
elif (not moving):
$Sprite.play("Stand")
print($Sprite.animation)
Could you please tell me where the bug is?
Thanking in advance,
Andrew27