Hi! I’m trying to use stacked sprites in Godot 4 for the first time using this tutorial
and some additional code to animate the character, however i’m running into an issue where the character keeps reverting to facing left whenever i let go off the keys. I want to make it so that it faces the direction it was moving in. any help? I’ve attached the code im using to try and do so and a gif of the issue as well.
tried it, didn’t work. if i take the first time i call the rotation out it still works the same, but if i take out the part i marked it stop sturning completely.
Keep the first one deleted, then print out the rotation of your stackedsprite in your if statement(after you set it) and again after all your methods ran. Check in the console if the values are correct throughout the course of the function
alright tried that
all the print stuff is showing null or blank statements nothing concrete i can use to see if the values are correct
i’ve noticed though when i remove all the code for animation it works perfectly fine, but when i put the animation code back in it does the weird left position thing, all the code for moving and animating the sprite attached below.
sorry for all the trouble, thanks for trying to help
It’s more helpful to paste the code. The </> button on the forum will make three ticks like so for formatting code
```
type or paste code here
```
You still have the first $StackedSprite.set_b_rotation(rotation) in this script. Might help to use if not input.is_zero_approx() instead of equivalence comparing vectors to zero.
#if input != Vector2.ZERO:
if not input.is_zero_approx():
It’s the same comparison, but computers handle floats (decimal numbers) in a weird way that ends up making actual exact zero hard to hit.
Also might be easier/better to use input vector function, depends on how you want diagonal inputs to work. Try it out, the difference is subtle. get_vector makes diagonal movement the same speed as axis-aligned, your method makes diagonal movement about 30% faster.
input = Input.get_vector("left", "right", "up", "down")
if not input.is_zero_approx():
good info to know for the future! but i tried this and nothing still the same
i think i might try moving things around a bit more and seeing what works what doesn’t. i had turned to the forum in despair lol, but maybe i might email the original person who gave me the animation code and see if he can figure it out too.