Determining the angle between two objects.
1. Calculate the Delta between the Origin and the Target
2. Use getangle to return the angle based on the Delta
Note: Delta = Final - Initial
PHP Code:
function getTargetAngle(origin, target) {
// Calculate Delta X and Y
temp.delta_x = target.x - origin.x;
temp.delta_y = target.y - origin.y;
// Return Angle Based on Delta
return getangle(temp.delta_x, temp.delta_y);
}
The above will return the correct angle towards the target object.
If you want the Graal direction, you can just swap out getangle with getdir and it'll return a number in |0,3|.
Also:
PHP Code:
function onWeaponfired() {
if (this.rocketfired == "1") {
this.rx = mousex;
this.ry = mousey;
onTimeout();
}
this.rocketfired = 1;
}
Would require you to fire it twice to actually fire it, and even then you could fire it as much as you wanted to mess it up while the rocket is in motion. You want to do something like this:
PHP Code:
function onWeaponfired() {
if (this.rocketfired == 0) {
this.rx = mousex;
this.ry = mousey;
this.rocketfired = 1;
onTimeout();
}
}
I would also suggest doing:
PHP Code:
function onTimeout() {
// other code...
if (this.rocketfired == 1) setTimer(0.05);
}
So your script only loops when it needs to.