I am making a game, as i recently learned javascript, and made a diep.io style character and a cannon ball. When u press a certain button, the cannon ball teleports to the cannon and sets its direction to the direction the cannon is facing. This was the method i used when i made scratch games when i was younger, so it was like instinct to do write that, but then realized there was no move forward or velocity function, anyone know how i can make something so the cannon moves in the direction of the cannon
Code:
Player:
if(isKeyDown(“a”)){
this.x -= 9;
}
if(isKeyDown(“d”)){
this.x += 9;
}
if(isKeyDown(“w”)){
this.y -= 9;
}
if(isKeyDown(“s”)){
this.y += 9;
}
Gun:
this.x = player.x;
this.y = player.y;
if(isKeyDown(“right”)){
this.rotation += 5
}
if(isKeyDown(“left”)){
this.rotation -= 5
}
Cannon ball:
if(isKeyDown(“up”)){
this.y = gun.y
this.x = gun.x
this.rotation = gun.rotation
}