Problem! with the frame designed

Godot Version

Replace this line with your Godot version

Question

is my code
extends CharacterBody2D

@export var SPEED = 300
@export var JUMP_VELOCITY : float = -450
var GRAVITY = ProjectSettings.get_setting(“physics/2d/default_gravity”)
@onready var animated_sprite_2d = $AnimatedSprite2D
var was_in_air : bool = false
var has_double_jump : bool = false
var animation_lock : bool = false

func _process(delta):
var input_vector = Vector2(
Input.get_action_strength(“move_right”) - Input.get_action_strength(“move_left”),
0
)
var direction = input_vector.x
if direction != 0 :
animated_sprite_2d.play(“RUN”)
animated_sprite_2d.flip_h = direction < 0
else:
animated_sprite_2d.play(“Idle”)
input_vector = input_vector.normalized() * SPEED
velocity.x = input_vector.x

if not is_on_floor() :
	velocity.y += GRAVITY * delta
	was_in_air =  true
else :
	has_double_jump = false
if was_in_air == true :
	land()
was_in_air = false

if Input.is_action_just_pressed("jump"):
	if is_on_floor() : 
		jump()
	elif not has_double_jump :
		velocity.y = JUMP_VELOCITY
		land()
		has_double_jump = true
move_and_slide()# 应用移动和滑动,不使用返回值
if animation_lock and !animated_sprite_2d.is_playing():
	animation_lock = false

func jump() :
velocity.y = JUMP_VELOCITY
animated_sprite_2d.play(“jump_start”)
animation_lock = true

func land() :
animated_sprite_2d.play(“jump_end”)
animation_lock = true
I do not know why I can not play my animation frames normally , as like as The land() fuciton , That "s three frames i was create , but is only one frame it can play which is frist.

Because first you run the land animation and then in next frame of process, its playing the walk animation. If you still unable to fix then write the codes in proper format:

``` codes... ```

actually is the problem of jump animation play, i don t why i set up the animation
but it can t be work or the frames work is imperfect , i write a check code to check this like this :
print("Current Animation: ", animated_sprite_2d.animation)
print("Animation Lock: ", animation_lock)
why i start game Current Animation “RUN” and “Idle” be work , but “jump_start” was not,and i wrtie a code like “jump was be used” its printf ,but the animation is t play

the land() funtion is mean the character drop


like this but you can see the when i pressed “jump” , the animation of jump_start
it was unappear

Ok, then can you show the codes in proper format here?

here is :extends CharacterBody2D

@export var SPEED = 300
@export var JUMP_VELOCITY : float = -450
var GRAVITY = ProjectSettings.get_setting(“physics/2d/default_gravity”)
@onready var animated_sprite_2d = $AnimatedSprite2D
var was_in_air : bool = false
var has_double_jump : bool = false
var animation_lock : bool = false

func _process(delta):
var input_vector = Vector2(
Input.get_action_strength(“move_right”) - Input.get_action_strength(“move_left”),
0
)
var direction = input_vector.x
if direction != 0 :
animated_sprite_2d.play(“RUN”)
animated_sprite_2d.flip_h = direction < 0
else:
animated_sprite_2d.play(“Idle”)
# 计算移动向量并应用速度
input_vector = input_vector.normalized() * SPEED
velocity.x = input_vector.x

if not is_on_floor() :
	velocity.y += GRAVITY * delta
	was_in_air =  true
else :
	has_double_jump = false
if was_in_air == true :
	land()
	was_in_air = false

if Input.is_action_just_pressed("jump"):
	if is_on_floor() : 
		jump()
	elif not has_double_jump :
		velocity.y = JUMP_VELOCITY
		land()
		has_double_jump = true
move_and_slide()# 应用移动和滑动,不使用返回值
if animation_lock and !animated_sprite_2d.is_playing():
	animation_lock = false
print("Current Animation: ", animated_sprite_2d.animation)
print("Animation Lock: ", animation_lock)

func jump() :
velocity.y = JUMP_VELOCITY
animated_sprite_2d.play(“jump_start”)
print(“jump was be used”)
animation_lock = true

func land() :
animated_sprite_2d.play(“jump_end”)
animation_lock = true

Actually i name a new variable “animation_lock”,maybe is the resource of problem?

To format your code properly, paste it between three ticks like so

```
    type or paste code here
```

results in:

    type or paste code here

You can click the </> button or ctrl+e in the forum to generate this for you.


It seems like you are always playing either the “RUN” or “Idle” animations, since they are part of _process this will play one of them every frame. You need to avoid playing these ground-based animations while the character is not on the floor.

1 Like

How can I do this?

I used this sign for it:
``` my codes ```

I set up :if not is_on_floor() :
velocity.y += GRAVITY * delta
was_in_air = true
else :
has_double_jumped = false
if was_in_air == true :
land()
was_in_air = false
I dont why my player under the ground he is still play the function land()

Well freinds, i solve the jump animtion problem , but now , i "I don’t know why my character keeps jumping 。

Here is the correct codes:

if is_on_floor():
   if direction != 0 :
      animated_sprite_2d.play(“RUN”)
      animated_sprite_2d.flip_h = direction < 0
   else:
      animated_sprite_2d.play(“Idle”)
...

Do you done it like that?

Actually i do like this
func updating_animation() :
if not animation_lock :
if not is_on_floor() :
animated_sprite_2d.play(“jump_loop”)
else :
if direction.x != 0 :
animated_sprite_2d.play(“RUN”)
else :
animated_sprite_2d.play(“Idle”)

The tutorial teached me i should code a “jump loop” to process when my Charcater was in abyess

1 Like