1

我有一个带有冰球(圆形夹具)和球棒(由用户的鼠标移动控制)的沙箱。如果用户击中冰球,我希望它根据鼠标移动速度获得脉冲。但是我有问题:

  • 在碰撞委托中,如果我检查蝙蝠的线速度,它要么是 0|0,要么是完全随机的(似乎)。
  • 如果我只是给冰球一个恒定的脉冲,球棒的移动速度是不包括在内的。
  • 我想在两个身体的接触点而不是冰球的中心施加脉冲。如果发生碰撞,有没有办法访问该点的坐标?

解决这个问题的正确方法是什么?

4

1 回答 1

0

通过查看 Farseer 的 XNA Samples 弄清楚了。您必须创建一个关节,更具体地说,是一个 FixedMouseJoint:

oPlayerJoint = new FixedMouseJoint( this.oPlayerBat, this.oPlayerBat.Position )
{
  MaxForce = 1000f * this.oPlayerBat.Mass
};
this.oWorld.AddJoint( this.oPlayerJoint );

然后在更新游戏逻辑时,如下所示:

MouseState oMouseState = Mouse.GetState();
Vector2 oMousePos = new Vector2(oMouseState.X - GAMEFIELD_WIDTH / 2f, oMouseState.Y - GAMEFIELD_HEIGHT / 2f);
// Make the bat follow the mouse.
this.oPlayerJoint.WorldAnchorB = oMousePos.ToPhysicsUnits();
于 2012-02-16T21:31:32.940 回答