- Joined
- Oct 19, 2024
Yep, that does make more sense. That said, I have a few personal preferences for doing things that might improve it a bit:Is there any reason the original would be preferable? It's always been my understanding that spamming if statements is considered bad practice, and I think my version improves readability too.
Firstly, using Input.get_axis() for input. If you have
Input.get_axis("left", "right)
, it returns 1 if you're holding right, -1 if holding left, and 0 if you're holding neither or both. It makes doing math-related stuff with movement a bit easier, but it might impact readability since you'd replace "left"
with movement.x < 0
for example. There's also a way to do animations that neatly handles all the edge cases, but it's a fair bit more complex and exclusive to Godot. Using the AnimationTree system you can do what your code does, and also strictly determine which animation to play if you're holding both Up and Right for example. This tutorial covers it, it was made during 3.2 but the code should (hopefully) still work for 4.0 and beyond.
I really wish I had a way to show my own projects to prove I'm not just Maldavius Figtree talking advice out of my ass, but I don't want to connect this account with any of my more personal ones cuz opsec.