• Question
  • how to make a projectile go in the direction the player is facing

like for example, if the player is facing northeast (or anywhere), the bullet will go in the direction of where the player is facing.

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);

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!

    L
    Last Chat :(
    See ya round, people.
    Aug 16, 2024
    T
    t43rew t34t3t45ret 45 e trsdyrt
    wt rtret
    Aug 14, 2024
    general
    Goodbye Gamelab Forum.
    Aug 12, 2024
    Not CDO chat
    yes
    Jul 25, 2024

    Chat

    Welcome to the Chat!

    Please select a channel or DM on the left.
    ;