In my current ai i need help with the pathfinding.The idea is that when cirle1 runs into circle2 it will find the distance to the opposite side of the circle2.After doing so it will get the use the “Math.atan2(Y,X)” function to get the angle to that spot.It will set its rotation so it is facing to percendicular the target spot, then it will start moving forward adjusting its rotation aong the way until it hits the target spot.Heres the code:
Pathfind = function (Clip, Check) {
[color=silver]// Stop all other move functions.//[/color]
Clip.Move = false;
[color=silver]// Set the x difference from the target x.//[/color]
var Xdiff = Check._x-Clip._x;
[color=silver]// Set the y difference from the target y.//[/color]
var Ydiff = Check._y-Clip._y;
[color=silver]// The total distance.//[/color]
var Distance = Math.abs(Math.sqrt((XdiffXdiff)+(YdiffYdiff)));
[color=silver]// Set target point x wise.//[/color]
Clip.Gox = Xdiff2;
[color=silver]// Set target point x wise.//[/color]
Clip.Goy = Ydiff2;
[color=silver]// If your within a specific distance.//[/color]
if (Distance>1) {
[color=silver]// Find angle.//[/color]
var Angle:Number = Math.atan2(Clip.Gox, Clip.Goy);
[color=silver]// Convert Angle.//[/color]
Angle = Angle180/Math.PI;
[color=silver]// Set rotation perpendicular to target coordinates.//[/color]
Clip._rotation = Angle-90;
[color=silver]// Move according to rotation x wise.//[/color]
Clip._x += Math.cos(Clip._rotation(Math.PI/180))3;
[color=silver]// Move according to rotation y wise.//[/color]
Clip._y += Math.sin(Clip._rotation(Math.PI/180))*3;
[color=silver]// Rotate along the semi circle.//[/color]
Clip._rotation -= (Angle-Clip._rotation)/16;
} else {
[color=silver]// If your within a specific distance.//[/color]
if (Distance<=1) {
[color=silver]// continue all other move functions.//[/color]
Clip.Move = true;
}
}
};