2012-12-28 41 views
7

我有一個長方體,正在從一個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; 

然後,我這樣做是爲了火了:

Body.ApplyLinearImpulse(new Vector2((float)Math.Cos(ang) * 100, (float)Math.Sin(ang) * 100)); 

我猜有一些設置或計算我忘了。

+2

如果您有空氣阻力,身體只會旋轉。我想你的模擬不能模擬大氣。 – phoog

+0

@phoog使這個答案 –

+0

你會如何去模擬在一個更古老的物理世界的氣氛? – Jastill

回答

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); 
    } 

而且ただ我們有一個旋轉物體。