Hello,

I have been trying to build a simple shooter game in which the player is moving forward constantly (to simulate flying), but can turn left or right to avoid objects. What I want to do is to have the airplane fixed in place so that when the player presses the keys to turn, the rest of the objects on the screen rotate around the player. I currently have this:

Code:

public function adjustFieldObjects(xSp, ySp) {
for (i=0; i<fieldObjectsArray.length; i++) {
var object = fieldObjectsArray[i];
radius = Math.sqrt(((object.x-fighter.x)*(object.x-fighter.x))+((object.y-fighter.y)*(object.y-fighter.y)));
//trace("radius",radius);
if(xRotation != oldXR) {
p = new Point(Math.cos(Math.atan2(object.y-fighter.y, object.x-fighter.x) +(Math.PI/144*xSp))*radius, Math.sin(Math.atan2(object.y-fighter.y, object.x-fighter.x) +(Math.PI/144*xSp))*radius);
//trace(p);
object.x = fighter.x-p.x;
object.y = fighter.y-p.y;
}
//object.x +=xSp;
object.y +=ySp;
}
oldXR = xRotation;
}
}

The problem is that the object seems to jump back and forth 180 degrees constantly. The object moves at a good speed around the player, in a full circle, but I can't for the life of me figure out why the object is jumping back and forth.

Just to break down the code: given the fixed position of the player and the position of the object, the distance between the two is calculated as the radius. The x and y difference between the two is then used to figure out the angle in radians that the two points make. The angle is added to by a set increment, multiplied by 1 or -1 (xSp) to give it a direction. Given the increment, the new angle can then be used to figure out the adjusted position of the object using Math.sin and Math.cos.

Does anyone else have any issues with this? Any suggestions would be greatly appreciated.

Thank you,

Maxwell

Essentially, the