【发布时间】:2014-03-12 01:23:00
【问题描述】:
我正在使用 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”是一个带有一堆不同矢量矩形的影片剪辑。
谢谢
【问题讨论】:
标签: actionscript-3 collision point hittest direction