我已经看到了一些关于这个主题的答案,但没有一个真正有太大帮助。
很简单,BoundingBox 碰撞。将原点设置为 0,0 时,碰撞发生得很好(至少对于我想要的那样)。当我将玩家的原点指定到中心时(因此它围绕中间旋转),碰撞似乎是偏移的,它在错误的时间检测到碰撞
代码(播放器类):
box = new BoundingBox(new Vector3(location, 0), new Vector3(location.X + texture.width, location.Y + texture.height, 0));
origin = new Vector2(texture.Width / 2, texture.Height / 2);
location.X += speed * (float)Math.Cos(rotation - anglecorrection);
location.Y += speed * (float)Math.Sin(rotation - anglecorrection);
public BoundingBox getBox()
{
return box;
}
代码(游戏)
BoundingBox box2 = new BoundingBox(new Vector3(location, 0), new Vector3(location.X + 30, location.Y + 30, 0));
if (player.getBox().Intersects(box2))
{
// Do Stuff
}
谢谢你的帮助 :)