How do I create rotational movement?
I'm making a game that needs to be able to make projectiles and enemies move toward any specific direction. Can someone help?
I'm making a game that needs to be able to make projectiles and enemies move toward any specific direction. Can someone help?
its complicated. it goes into trigonometry and stuff like sin cos and tan. ill explain each step one by one but you will probably need to dive deeper yourself.
---------------------------------------------------------------
in order to get the angle use the atan2d function like this.
atan2d((target x - my x ),( target y - my y))
this returns the angle.
----------------------------------------------------------------
to get the direction to travel you plug them into sin (sin for y) and cos (cos for x) using functions like these.
x += cos(angle)
y += sin(angle)
this should move them 1 in the correct direction.
it only moves them exactly 1 so if you need them to move lets say 5 then multiply them BOTH by 5.
---------------------------------------------------------------
hope that helps
don't worry about it being hard. i learned it last year and its still pretty difficult for me. once you learn the basics it gets easier from there.
Thanks. I'll try this in the future.