Ok, so i am working on a car game, and i have soem AI here, makes the car go to the waypoints, but, when the car gets to the third waypoint. it starts to twist and turn, then it straightens out.
the script:
onClipEvent (load) {
var wayPointX:Array = new Array(“344”, “10”, “18”, “346”);
var wayPointY:Array = new Array(“242”, “231”, “448”, “453”);
var newRot:Number = 0;
var mySpeed = 0;
var myfSpeed:Number = 1.1;
var myrSpeed:Number = .9;
var curSpot = 0;
var turnSpeed = 3;
}
//onEnterFrame = function(){
onClipEvent (enterFrame) {
if (curSpot>wayPointX.length-1) {
curSpot = 0;
}
xDiff = this._x-wayPointX[curSpot];
yDiff = this._y-wayPointY[curSpot];
distance = Math.sqrt(Math.round(xDiffxDiff+yDiffy Diff));
newRot = Math.atan2(yDiff, xDiff)(180/Math.PI);
mySpeed += myfSpeed;
difference = newRot-_rotation-90;
if (difference>60) {
//myfSpeed = .8;
//turnSpeed = 6;
} else {
//myfSpeed = 1.1;
//turnSpeed = 3;
}
if (distance<=150) {
myfSpeed = distance/175;
} else {
myfSpeed = 1.1;
}
//if (this._rotation<difference) {
//this._rotation -= turnSpeedmySpeed/7;
//}
//if (this._rotation>difference) {
//this._rotation += turnSpeedmySpeed/7;
//}
this._rotation += difference/2+turnSpeed;
this._y += Math.cos(this._rotation(Math.PI/180))m ySpeed-1;
this._x += Math.sin(this._rotation*(Math.PI/180))*m ySpeed;
if (mySpeed<=0.3 && mySpeed>=-0.3) {
mySpeed = 0;
}
mySpeed *= .91;
if (distance<=10) {
curSpot += 1;
}
}
also, i’d like it to rotate as it moves., not rotate and then move