Hi again guys!
I really don’t how to come around this problem for this one!
I got a enemy (ghost) that is tracking the player, on this one thing my script to follow the player is working well. But i’ve inserted a function to hitTest with the wall around (I use a MC with an alpha at 0 to serve as an obstacle).
Problem is that the ghost is stopped by the mc boundary alrigth but if the player go around this MC, the ghost will actually find it’s way to the player but is shuddering in the wall like crazy! I would to know if any of ya can help me find a way to ease that shuddering ?
Here is my Ghost Class :
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.geom.Point;
public class Ghost extends MovieClip
{
private var speed:Number = 4;
private var hitRadius:Number = 40;
public function Ghost(xPos:Number, yPos:Number)
{
x = xPos;
y = yPos;
}
public function FollowPlayer(target:MovieClip):void
{
var targetX:int = target.x - x;
var targetY:int = target.y - y;
rotation = Math.atan2(targetY, targetX) * 180 / Math.PI;
var vx:Number = speed * (90 - Math.abs(rotation)) / 90;
var vy:Number;
if(rotation < 0)
vy = -speed + Math.abs(vx); // Going upwards
else
vy = speed - Math.abs(vx); //Going Downward;
x += vx;
y += vy;
}
public function DetectWall(obstacle:MovieClip):void
{
while(obstacle.hitTestPoint(x, y+hitRadius, true))
{
y--;
}
while (obstacle.hitTestPoint(x, y-hitRadius, true))
{
y++;
}
while (obstacle.hitTestPoint(x-hitRadius, y, true))
{
x++;
}
while (obstacle.hitTestPoint(x+hitRadius, y, true))
{
x--;
}
}
}
}
The obstacle parameter is the mc that i use for the hittesting!
Thanks all in advance !!!