Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | MegamanXfangamer |
Hello! it is me again.
I have another question and it is related to the animations of my platform character and it is that no animation works as it should or I don’t know if I have indicated it incorrectly,
when the character jumps the jump animation doesn’t work correctly, and the wall slide animation doesn’t advance it’s three frames but being on the wall only the first frame is shown and also the falling animation doesn’t show as it should you can copy the code and make the animations so you can see why it doesn’t work, when the character jumps the jump animation doesn’t work correctly, and the wall slide animation doesn’t advance it’s three frames but being on the wall only the first frame is shown and also the falling animation doesn’t show as it should you can copy the code and make the animations so you can see why it doesn’t work, I would greatly appreciate it
Here is the code of the character
extends KinematicBody2D
export (int) var speed = 175
export (int) var jump_speed = -400
export (int) var gravity = 800
const wall_slide_speed = 82.5
const wall_slide_gravity = 400
var is_wall_sliding : bool = false
var velocity = Vector2.ZERO
func get_input():
velocity.x = 0
if Input.is_action_pressed("ui_right"):
velocity.x += speed
$AnimatedSprite.flip_h = false
$AnimatedSprite.play("RUN")
elif Input.is_action_pressed("ui_left"):
velocity.x -= speed
$AnimatedSprite.flip_h = true
$AnimatedSprite.play("RUN")
elif velocity.y < 0:
$AnimatedSprite.play("JUMP")
elif velocity.y > 0:
$AnimatedSprite.play("FALL")
elif is_on_wall() and velocity.y > 0:
$AnimatedSprite.play("WALL_SLIDE")
else:
$AnimatedSprite.play("IDLE")
func _physics_process(delta):
get_input()
velocity.y += gravity * delta
velocity = move_and_slide(velocity, Vector2.UP)
if Input.is_action_just_pressed("ui_up"):
if is_on_floor():
velocity.y -= 400
$AnimatedSprite.play("JUMP")
if is_on_wall() and not is_on_floor():
if Input.is_action_pressed("ui_right") or Input.is_action_pressed("ui_left"):
is_wall_sliding = true
else:
is_wall_sliding = false
else:
is_wall_sliding = false
if is_wall_sliding == true:
velocity.y += wall_slide_gravity * delta
velocity.y = min(velocity.y, wall_slide_speed)
$AnimatedSprite.play("WALL_SLIDE")
If you write more legibly we can help.
like this
func examples():
blabla
ramazan | 2022-03-23 08:59
If you highlight your code and click the {} button it will make the code legible for us. Also it would be helpful if you could explain how your animation isnt working, do you mean you get the wrong animation or it starts to play and then stops or restarts again?
Gluon | 2022-03-23 19:52
I updated the question
MegamanXfangamer | 2022-03-23 22:06
func _physics_process(delta):
// current.animation
//we must find current animation
print($AnimatedSprite.name) // name of the animation playing
//forgot the code
// query the name of the animation that is playing at that moment.
// You will find the source of the problem
ramazan | 2022-03-23 22:17