Here are some snippets from one of my car scripts.
To move in direction of angle:
PHP Code:
temp.newx = player.x + (this.graalspeed * cos(this.angle));
temp.newy = player.y + (this.graalspeed * -sin(this.angle));
To accelerate:
PHP Code:
function Accelerate()
{
this.smod = 0;
this.speed += (this.speed < this.maxspeed) ? 0.20 : 0;
}
Turns:
PHP Code:
function LeftTurn()
{
this.angle += degtorad(this.turnpower);
if (radtodeg(this.angle)+this.turnpower <= 0)
{
this.angle = degtorad(360);
}
if (radtodeg(this.angle)+this.turnpower >= 360)
{
this.angle = degtorad(0);
}
}
function RightTurn()
{
this.angle -= degtorad(this.turnpower);
if (radtodeg(this.angle)+this.turnpower >= 360)
{
this.angle = degtorad(359);
}
if (radtodeg(this.angle)+this.turnpower <= 0)
{
this.angle = degtorad(360);
}
}