Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | PabloSa00 |
Hi! First of all, sorry for disturbing, I am just starting at this and maybe my problem is too noobish heh, I am currently facing a problem where I can’t a way to play my animation “Jump”
extends CharacterBody2D
var speed := 120
var direction := 0.0
var jump := 250
const gravity := 9
@onready var anim := $AnimationPlayer
@onready var sprite := $Sprite2D
func _physics_process(delta):
direction = Input.get_axis("ui_left","ui_right")
velocity.x = direction * speed
if is_on_floor() and Input.is_action_just_pressed("ui_accept"):
velocity.y -= jump
if !is_on_floor():
velocity.y += gravity
move_and_slide()
func _process(delta):
if Input.is_action_pressed("ui_left"):
anim.play("Walk")
sprite.flip_h = true
elif Input.is_action_pressed("ui_right"):
anim.play("Walk")
sprite.flip_h = false
elif Input.is_action_just_pressed("ui_accept"):
anim.play("Jump")
else:
anim.play("Idle")
I have tried placing it in different location like: under velocity.y -= jump, before velocity.y += gravity, etc but nothing seems to work, thank you in advance, have a good day
Edited to fix forum code formatting.
jgodfrey | 2023-05-26 02:48