Discord
Login
Community
DARK THEME

Projectiles with different directions

I have this project that are some simple physics for airplanes, and now I would like to add in the 2.0 bullets, but I do not know how to make bullets in this case.

The plane has a variable that is its angle, but unlike Scratch, in microStudio I don't know how to move an object giving it a direction.

Is there any way to do this?

Thanks!

https://microstudio.dev/i/The_bit_cat/planes/

You can assign each projectile an x and y velocity and change its position each frame.

Projectile = class
  constructor = function(x=0, y=0, vx=0, vy=0)
    this.x = x
    this.y = y
    this.vx = vx
    this.vy = vy
  end
  
  update = function()
    x += vx
    y += vy
  end
  
  draw = function()
    screen.drawSprite("projectile", x, y, /* projectile sprite size */)
  end
end

https://microstudio.io/i/Loginus/actoratan2bullet/

  vx = sind( angle )
  vy = cosd( angle )

Thank you!

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community