Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Body not rotating to face downward with gravity

Tags:

c#

farseer

I have a rectangle body that is being fired from a canon at a 45degree Angle. The body is also rotated up at a 45 degree angle and I have set the mass to be at the front of the body.

The body goes up in the air fine, however, as the body comes back down to earth it does not rotate. Is there a way so that the mass side comes down first?

My real world example is, throwing a tennis ball with a string attached into the air. Currently the string doesn't fall behind the ball when gravity comes into affect.

Here is my 'ball'

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;

Then I do this to fire it:

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

I am guessing there is some setting or calculation I am forgetting.

like image 864
Jastill Avatar asked Dec 28 '12 08:12

Jastill


People also ask

Can gravity exist without rotation?

No, the Earth has gravity just because it has mass. It would have almost exactly the same gravity even if it wasn't spinning at all. The gravitational effects of its spin are extremely subtle, and have not yet been reliably measured.

Can a body rotate about center of gravity?

An object can rotate about any axis. However, in the case where the axis does not go through the center of gravity, we would typically decompose this motion into a movement of the object's center of gravity, combined with motion about the center of gravity. You can always do this.

Can a body rotate under the influence of its own weight?

Answer: No, body can not rotate about its center of gravity because center of gravity is point about which whole weight of body act ( where the weight is balance ) . The line passing through the axis of rotation the torque acting is zero .

Does Earth rotate due to gravity?

Solution : Due to rotation of earth about its axis effective acceleration due to gravity decreases. This effect seems zero at poles and maximum at equator.


1 Answers

For anyone who will read this in the future, I did work it out.

I realized that the velocity would be changing in a similar fashion as I wanted the rotation to change. So I based the rotation on the velocity, the more gravity pulls down the more the object will turn to face down.

In my objects update class, I put the following (note: potentially bad maths)

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

And ta da we have a rotating object.

like image 179
Jastill Avatar answered Oct 02 '22 10:10

Jastill