- Edited
NJL64 Get the angle of the velocity vector and snap it to 45 deg increments.
I think I answered very similar question(s) couple of times already in the past
Take a look here:
https://godotforums.org/d/38606-8-directional-input/2
NJL64 Get the angle of the velocity vector and snap it to 45 deg increments.
I think I answered very similar question(s) couple of times already in the past
Take a look here:
https://godotforums.org/d/38606-8-directional-input/2
xyz Sorry. I know you said you answered similar questions already, but I was wondering if you could help me understand a way to apply this to my function?
Mine's not for inputs, but rather just the character moving in general.
I just thought I'd ask ahead of time in case I have trouble. I'm researching some of this stuff right now and thinking of how to apply it to my script.
When I get the angle of the velocity vector and snap it to 45 degrees, what should I do with it then? (I'm still brushing up on my Vector math)
I would really appreciate it.
xyz So I tried this:
func get_dir():
var dir = velocity
var angle = posmod(rad_to_deg(dir.angle()), 360)
var sector = wrapi(snapped(angle, 45) / 45, 0, 8)
return ["E", "SE", "S", "SW", "W", "NW", "N", "NE"] [sector]
and this:
dir_last = get_dir()
and it works for input and seems to work for bouncing off of things! But if I could fix one last issue, it should work how I want it.
Unfortunately I can no longer say
velocity = dir_last * speed
when shooting my character in the direction facing using the "BLAST" state.
If you would be so, SO generous to help me with with an alternative so that I can still shoot the character in the direction they are facing, it would really help me out.
Thank you!
xyz @DaveTheCoder Thank you!