Я использую hitTestPoint для обнаружения столкновений между врагом и стеной.As3: получить точную точку столкновения с помощью hitTestPoint?
Я хочу, чтобы, если враг коснется стены, его новое направление цели должно быть изменено на точку в направлении противоположного направления стены. Чтобы сделать это, я думаю, мне нужно точно знать, где столкнулся враг и стена.
Основная система движения:
private function move(event:Event):void
{
var dx = target.x - x;
var dy = target.y - y;
var angle = Math.atan2(dy, dx)/Math.PI*180;
rotation = angle;
this.x = x+Math.cos(rotation/180*Math.PI)*movementSpeed;
this.y = y+Math.sin(rotation/180*Math.PI)*movementSpeed;
var hyp = Math.sqrt((dx*dx)+(dy*dy));
if(hyp <5)
{
target.x = Math.floor(Math.random() * (1750 - 50 + 1) + 50);
target.y = Math.floor(Math.random() * (850 - 50 + 1) + 50);
}
}
И система обнаружения стены:
while (_root.wall.hitTestPoint(this.x, this.y+radius, true))
{
this.y--;
target.y = Math.floor(Math.random() * (850 - 50 + 1) + 50);
}
while (_root.wall.hitTestPoint(this.x, this.y-radius, true))
{
this.y++;
target.y = Math.floor(Math.random() * (850 - 50 + 1) + 50);
}
while (_root.wall.hitTestPoint(this.x-radius, this.y, true))
{
this.x++;
target.x = Math.floor(Math.random() * (1750 - 50 + 1) + 50);
}
while (_root.wall.hitTestPoint(this.x+radius, this.y, true))
{
this.x--;
target.x = Math.floor(Math.random() * (1750 - 50 + 1) + 50);
}
"_root.wall" является мувиклип с кучей различных векторных прямоугольников.
Спасибо