|
|
|
|
Reply From: |
ChristianSF |
Have you checked that your jump animation is correctly set up, i.e. does it work properly in the Animations/Animations Frames section?
Maybe you just forgot to add the rest of the animation images or named the animation differently (not “JUMP”)? Hard to tell from here.
EDIT:
Just saw your example animation. Your code
if not is_on_floor():
$Sprite.play("JUMP")
keeps restarting the jump animation several times per second, which is probably why you don’t see any other frames of it.
Hey,
For the first part of tour answer, yes the animation of the jump working in the animation editor
for the second part, how can i make it not to restart?
shugishugi | 2020-07-27 18:20
Well, one easy way, as I imagine, would be to add a variable jump_ani_playing
, setting it to false as default value and only to true once the player char has left the ground (not hundreds of times each frame ).
Then change your existing code to:
var jump_ani_playing = false
... # The following is in your physicsprocess function:...
if !is_on_floor() and !jump_ani_playing:
$Sprite.play("JUMP")
jump_ani_playing = true
So, when the player char lifts off for the first time, is_on_floor()
returns false
and jump_ani_playing
is also still false
, so the sprite will start playing its JUMP animation.
We set jump_ani_playing
to true
immediately afterwards, so that the next time the function runs, the IF statement as a whole will resolve to false and not restart the animation.
Should work (untested), but probably there are dozens of better ways to do that.
EDIT: For some reason, this Q&A system took the underscores in the variable names within my comment for “show this in italics”. Modified the comment using the code feature for clarity.
ChristianSF | 2020-07-27 19:27
hi ChristianSF,
thanks for the help, but still, not working.
what hapenning now is that when i jump it plays the walk animation or the idle animation (if i jump just up)
var jump_ani_playing = false
var velocity = Vector2(0,0)
const SPEED = 295
const GRAVITY = 30
const JUMPFORCE = -780
func _physics_process(delta):
if Input.is_action_pressed("ui_right"):
velocity.x = SPEED
$Sprite.flip_h = false
$Sprite.play("WALK")
elif Input.is_action_pressed("ui_left"):
velocity.x = -SPEED
$Sprite.flip_h = true
$Sprite.play("WALK")
else :
$Sprite.play("IDLE")
velocity.y = velocity.y + GRAVITY
if Input.is_action_just_pressed("ui_up") and is_on_floor():
velocity.y = JUMPFORCE
if !is_on_floor() and !jump_ani_playing:
$Sprite.play("JUMP")
jump_ani_playing = true
velocity = move_and_slide(velocity,Vector2.UP)
velocity.x = lerp(velocity.x,0,1)
shugishugi | 2020-07-28 19:58