Setting up a simple physics scene...

Mar 5, 2009 at 5:02 PM
Edited Mar 5, 2009 at 5:15 PM
I am having trouble setting up a simple physics scene.... all I am trying to do is create a beam on which a ball can balance.... the beam is static and the ball is not. I effect the rotation of the beam to make the ball roll but I am having a few different problems which I am sure are just user error so if someone more experienced with this physics system could help me out that would be great!

PROBLEMS
  1. The ball seems to slide an awful lot on the beam; I have tried cranking up the friction on both Geoms a lot but it seems that if it gets high enough to prevent the ball from slipping then it causes a random crash with a float value going NaN.
  2. Everything in general seems very "slow", the ideal effect I am trying to get is something simular to the feeling of the balance beam in this flash game: http://www.zanorg.com/prodperso/jeuxchiants/doublejeu.htm
Here is how I setup the ball:

            this.CollisionBody = BodyFactory.Instance.CreateCircleBody(this.BallOrigin.X, 0.5f);
            this.CollisionBody.MomentOfInertia = 5;

            this.CollisionGeometry = GeomFactory.Instance.CreateCircleGeom(this.CollisionBody, this.BallOrigin.X, 60);
            this.CollisionGeometry.FrictionCoefficient = 1;

And here is how I setup the beam:

           Vertices verts = Vertices.CreateRectangle(this.BeamTexture.Width, this.BeamTexture.Height);
            verts.SubDivideEdges(5);

            this.CollisionBody = BodyFactory.Instance.CreatePolygonBody(verts, 1);
            this.CollisionBody.IsStatic = true;

            this.CollisionGeometry = GeomFactory.Instance.CreatePolygonGeom(this.CollisionBody, verts, 5);
            this.CollisionGeometry.FrictionCoefficient = 5;

The reason I sub-divide the beam is because I was getting some penetration issues which seem to be resolved after creating it as a polygon.

EDIT: Also, after I effect the rotation of the static beam I call the PhysicsSimulator.Update(elapsed); method but it seems it takes numerous frames to solve the collision. I have a feeling I am going about this scene all wrong. If somone could show me the correct way to set something like this up that would be great

Mar 6, 2009 at 5:33 PM
why are you setting the MomentOfIntertia of the CollisionBody, if you are using the CreateCircleBody method?
keep in mind: A BODY IS JUST A POINT! the creator methods are only convenience methods to calculate a good MomentOfInertia.
otherwise you may want to just use the CreateBody method and set the MomentOfInertia in the the constructor.

if this doesn't solve the problem, setup your scene in a Demo of the SimpleExamples and post it on the forum, making it easier for others to figure things out.
Mar 6, 2009 at 5:39 PM
I have tried it with and without that line of code. The main reason for changing it was it was almost impossible to get it to rotate without sliding before making that change so I figured it was worth a try. I have pretty much given up on the fact of getting it to roll on the platform without sliding so I have just turned down the friction and made it slide though I am still getting penetration issues with the circle on the platform...
Mar 6, 2009 at 5:58 PM
there is a chapter about penetration issues in the Farseer Manual (pg. 32 - Knowns issues -> Tunneling; Geometries going into each other) which you may consult
Mar 6, 2009 at 6:02 PM
Edited Mar 6, 2009 at 6:04 PM
I really do not understand what I am doing wrong here.... here is all the relative code of what is happening...

// Create the physics simulator with the desired gravity
this.PhysicsSimulator = new DreamscapeEngine.Physics.PhysicsSimulator(new Vector2(0, 1000));

// Create the balance ball object which gets added to the physics simulator in the initialize method
this.CollisionBody = BodyFactory.Instance.CreateCircleBody(25, 0.5f);

this.CollisionGeometry = GeomFactory.Instance.CreateCircleGeom(25, 20);
this.CollisionGeometry.FrictionCoefficient = 0.1f;
this.CollisionGeometry.RestitutionCoefficient = 0.5f;

// The balance beam object which uses a fixed revolute joint to lock it into position and an angular spring which I change the TargetAngle on to force the beam to rotate
            this.CollisionBody = BodyFactory.Instance.CreateRectangleBody(
                500, 
                16, 
                1);
            //this.CollisionBody.IsStatic = true;

            this.CollisionGeometry = GeomFactory.Instance.CreateRectangleGeom(
                this.CollisionBody, 
                this.BeamTexture.Width, 
                this.BeamTexture.Height);
            this.CollisionGeometry.FrictionCoefficient = 0.1f;

            this.AngularSpring = SpringFactory.Instance.CreateFixedAngleSpring(
                this.CollisionBody,
                10000000,
                1000000);

            this.RevoluteJoint = JointFactory.Instance.CreateFixedRevoluteJoint(this.CollisionBody, Vector2.Zero);

Now for the most part everything works fine but there are issues with for example just testing I drop a ball from about 500 units (pixels) above the beam and there is about a 25% chance it is going to go through the beam... are there some settings I can tweak to help prevent this... should I go back to sub-dividing the rectangle edges?
Mar 6, 2009 at 6:12 PM
Edited Mar 6, 2009 at 11:29 PM
nm serious flawed logic in that last post lol