system
June 25, 2022, 8:45pm
1
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
chris33556
hey all,
i’m animating a sprite to walk and stand idle. i managed to get the sprite to walk left and right and stand idle. but when i try to make the sprite move up and down, the sprite doesn’t animate the Walk sequence. please note this gif example of the problem:
here is the code on pastebin:
much help would be appreciated thanks
system
June 25, 2022, 10:55pm
2
Reply From:
newgodot_user
if Input.is_action_pressed("ui_right") and Input.is_action_pressed("ui_left"):
velocity.x = 0
elif Input.is_action_pressed("ui_right"):
velocity.x = SPEED
animatedSprite.animation = "Walk"
elif Input.is_action_pressed("ui_left"):
velocity.x = -SPEED
animatedSprite.animation = "Walk"
else:
velocity.x = lerp(velocity.x,0,0.1)
animatedSprite.animation = "Idle"
if Input.is_action_pressed("ui_up") and Input.is_action_pressed("ui_down"):
velocity.z = 0
elif Input.is_action_pressed("ui_up"):
velocity.z = -SPEED
animatedSprite.animation = "Walk"
elif Input.is_action_pressed("ui_down"):
velocity.z = SPEED
animatedSprite.animation = "Walk"
else:
velocity.z = lerp(velocity.z,0,0.1)
if velocity.x > 0:
animatedSprite.flip_h = false
elif velocity.x < 0:
animatedSprite.flip_h = true
Well, from what I can see, you have the same animation as the animation for walking left or right set for walking up or down.
thanks for your reply .
so i’ve updated the script and got the character to move and stop as expected.
here is the updated script:
updated script 26_06-2022 - Pastebin.com
however now, im trying to add the command to normalize the diagonal directions which is:
velocity = velocity (normalized) to the script.
when i place it into the script and run the game, the character moves as expected but when stopping , he continues to slide along the ground.
where do i add the line into the script. any ideas?
chris33556 | 2022-06-26 09:23
no not really, sorry.
newgodot_user | 2022-06-26 11:43