身体不会因重力而面朝下旋转

Jas*_*ill 7 c# farseer

我有一个长方体,从45度角的佳能射出.身体也以45度角向上旋转,我已将质量设定在身体的前部.

然而,身体在空气中上升,当身体回到地面时,它不会旋转.有没有办法让大众方面先下来?

我的现实世界的例子是,扔一个带有绳子的网球.目前,当重力发挥作用时,弦不会落在球后面.

这是我的'球'

Body = BodyFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(texture.Width), ConvertUnits.ToSimUnits(texture.Height),100f, postition, this);
Body.Mass = 1;
Body.LocalCenter = new Vector2(ConvertUnits.ToSimUnits(Texture.Width), ConvertUnits.ToSimUnits(Texture.Height / 2));
Body.UserData = this;
Body.BodyType = BodyType.Dynamic;
Body.CollisionCategories = Category.All;
Body.CollidesWith = Category.All;
Body.IgnoreGravity = false;
float ang = BarrelJoint.JointAngle;
Body.Rotation = ang;
Run Code Online (Sandbox Code Playgroud)

然后我这样做解雇它:

Body.ApplyLinearImpulse(new Vector2((float)Math.Cos(ang) * 100, (float)Math.Sin(ang) * 100));
Run Code Online (Sandbox Code Playgroud)

我猜我有一些设置或计算我忘了.

Jas*_*ill 1

对于将来会读到这篇文章的人来说,我确实解决了这个问题。

我意识到速度会以类似的方式改变,就像我想要改变旋转一样。因此,我根据速度进行旋转,重力越大,物体就越会面朝下。

在我的对象更新类中,我输入了以下内容(注意:数学可能很糟糕)

public override void Update(GameTime gameTime)
    {
        Vector2 velocity = Body.LinearVelocity;

        float radians = (float)(Math.Atan2(-velocity.X, velocity.Y) + Math.PI/2.0);

        Body.Rotation = radians;

        base.Update(gameTime);
    }
Run Code Online (Sandbox Code Playgroud)

哒哒我们有一个旋转的物体。