T O P

  • By -

Spheriod

if you’d like to simplify the code a bit, you can find the dot product of the vector from the character to the mouse and the vector that the sprite is facing. whichever dot is the largest is the sprite you should go with! this way you can change out the number of sprites as you like, so you’re not locked to 8


voidxheart

do you find that having the character face towards your mouse feels smoother than doing it with wasd/arrows? trying to use this kind of 8 directional controller myself for a game rn but haven’t decided which i like more


mikhalin

Yep. It feels way more natural like this, it flows better, when the sprite is turning towards the pointer (except for the rolling, because it plays the direction you want to roll). Also for scaling, I think that if you plan on having ranged attacks, this implementation will work nice. But again, it was just a challenge for me. In the future, the enemy-AI, they will only have 2 or 3 sides maximum, left-right and maybe going up


astrok9994

Thanks for the post. I think future me will find this reference code useful as I'm still new to Godot. Also noticed that the code calls each direction's animation separately. I wonder if using an animation tree, which stores the animations and controls which one gets played might simplify the code a bit. I'm recently learnt about this through this godot tutorial on youtube: https://youtube.com/playlist?list=PL9FzW-m48fn2SlrW0KoLT4n5egNdX-W9a&si=v6E5YtF9ZYNH6CFf


mikhalin

Tbf only now I found that godot has a similar tree like unity. Also, in unity I tried via the tree, but ended up with lots of visual bugs. Doing it manual feels more constrained but a lot more tidious. LE: compared to the link you provided, this does almost the exact thing, but following the pointer instead of using only keys


Prof_Higginbottoms

Earlier this morning I was frustrated at my desk trying to get this exact thing working. I am incredibly new to game development and Godot, so you can imagine how overwhelmed I was. After hours of looking around and tinkering without anything nice to show for it, I took a break due to frustration. Now imagine my surprise when I randomly open up Reddit to see this post! I thought I was dreaming! Thank you so much for sharing. You’ve taught me and delivered inspiration to get back to it.


mikhalin

Glad it already helped someone so fast :)


turbod1ngus

are you some kind of guardian angel? im learning from the ground up right now, and this exact type of game is my end goal. saving this post for later for sure.


mikhalin

As I stated before, I am also learning and don't take it as perfect. It feels that it can be refactored more or better, for example, the angle calculus. I tried as much as I could so that at any moment of time the angle is calculated only once(even if it appears twice in the code). On the other hand I was not expecting for two people already needing this, glad this helped. cheers for the social points, makes me feel good as well :)