我在做塔防游戏,我用的是stencyl。
我想做一个像(部落冲突)这样的2d塔防游戏,所以我想知道如何使用像(部落冲突中的佳能)这样的框架来制作一个指向物体的炮塔。
我的意思是,当一个物体进入塔的范围时,塔将指向它,而不是旋转塔,而是使用2d框架,通过某种方式,使用代码或数学方法。
发布于 2019-06-11 15:46:31
我已经找到解决方案了。执行以下操作:
float Direction = 0;
float FinalDirection = 0;
float DirectionDegree = 0;
int NumberOfDirections = 0; // eg: 24 or 32 or even 128 or anything Directions
DirectionDegree = 360 / NumberOfDirections;
void update() // this will run every frame
{
Direction = Math.atan2(target.y - tower.y, target.x - tower.x ) * (180 / Math.PI);
if(Direction < 0)
{
Direction += 360;
}
FinalDirection = Direction / DirectionDegree;
tower.frame = FinalDirection;
}https://stackoverflow.com/questions/56483375
复制相似问题