like for example, if the player is facing northeast (or anywhere), the bullet will go in the direction of where the player is facing.
how to make a projectile go in the direction the player is facing
ackvonhuelioLvl 41
- Best Answerset by pluto
to find the direction:
var dir = atan2(target.y-player.y,target.x-player.x);
atan2(y2-y1,x2-x1) returns the direction from (x1,y1) to (x2,y2) as an angle(0-360).
to make the projectile move at this angle:
projectile.x += cos(dir);
projectile.y += sin(dir);
VarrienceLvl 25
- Edited
yea that's how it works.... though if your doing this on CDO Gamelab you can just use the builtin .setSpeedAndDirection and you should just be able to include the .angle the sprite you want to shoot in the direction that is if your feeling lazy but of best of luck!
ackvonhuelioLvl 41
- iPhone
Varrience
🤮
FluffypoopoLvl 55
with majajec
FluffypoopoLvl 55
I am aware it is magic