I am planning on making a completely space-based game (like
Cosmic Rift or Starship Troopers (Cosmic Rift is going P2P and Starship Troopers went out of business)), but I really can't think of a way to make the movement work correctly with my limited math knowledge. I'll attach a level with what I have of the movement system so far, and also paste the code below.
NPC Code:
//#CLIENTSIDE
if (created) {
disabledefmovement;
showstats 0;
this.speed = 0;
this.dir = 0;
}
if (playerenters || timeout) {
//all
PI = 3.1415926535897932384626433832795;
this.rotatespeed = 0.1;
//normal
this.maxspeed = 1;
this.thrustspeed = 0.05;
this.turnspeed = 0.07;
//hyper
this.hypermaxspeed = 1.3;
this.hyperthrustspeed = 0.1;
this.hyperturnspeed = 0.02;
if (keydown(1))
this.dir = (this.dir+this.rotatespeed)%(PI*2);
if (keydown(3))
this.dir = (this.dir-this.rotatespeed)%(PI*2);
if (keydown(0) || keydown(2)) {
newspeed = this.speed+this.thrustspeed*(keydown(0)-keydown(2));
if (newspeed in <this.maxspeed*-1,this.maxspeed>) {
this.speed = newspeed;
}
this.angle = this.dir;
}
playerx += sin(this.angle)*this.speed;
playery += cos(this.angle)*this.speed;
for (i = 0;i<3;i++) {
showimg 200+i,@tempus sans itc@c@.,playerx+sin(this.dir)*(i*2),playery+cos(th is.dir)*(i*2);
changeimgcolors 200+i,0,0,2,.99;
changeimgvis 200+i,3;
}
temp();
timeout = .05;
}
function temp() {
if (keydown(5)) this.dir = (this.dir+PI)%(PI*2);
showimg 0,@#v(sin(this.angle)),10,50;
showimg 1,@#v(sin(this.dir)),10,70;
showimg 2,@#v(cos(this.angle)),10,90;
showimg 3,@#v(cos(this.dir)),10,110;
for (i = 0;i<50;i++)
changeimgvis i,4;
}