For the last 2 days I've tried to get this working.
I've got it all setup. Created an instance of PhysicsSimulator, some bodies and geometry.
But collision seem to be very bad, and I get some other weird behaviour.
GameObject goNewBody = new GameObject();
goNewBody.Height = 64;
goNewBody.Width = 64;
goNewBody.TheSprite = GetSprite("test.png");
goNewBody.Body = BodyFactory.Instance.CreateRectangleBody(PhysicsEngine, goNewBody.Width, goNewBody.Height, 1);
goNewBody.Geometry = GeomFactory.Instance.CreateRectangleGeom(PhysicsEngine, goNewBody.Body, goNewBody.Width, goNewBody.Height, 1);
goNewBody.Geometry.FrictionCoefficient = 0.8f;
goNewBody.Body.IsStatic = false;
goNewBody.Body.Position = new Vector2(0, 0);//new Vector2(512, 128);
//goNewBody.Body.Rotation = AdvanceMath.MathHelper.RadiansPerDegree * 45;
GameObject is a class that contains information about the object, and stores information on what to draw, etc. (I'm using C# and OpenGL (SDL.NET))
test.png is a simple png file, 64x64. (It's a crate).
I recently changed the gravity to 10,10 to see how the engine would behave.
PhysicsEngine = new FarseerGames.FarseerPhysics.PhysicsSimulator(new Vector2(10, 10));//(new Vector2(0, 900));
I've also tried changing PhysicsEngine.Iterations, etc.
The boxes starts floating from top left towards bottom right. That looks all fine, but as soon as they collide with the floor I have, they bounce off, going up, then suddenly changes direction downwards again, and they continue like that, like saw teeth.
And the boxes seem to have no corners, etc. They stand on top of each other just fine, but slides off, and cuts through the corners.
The floor is just a 1024x64 box, created just like the crates.
I am drawing the boxes, with the center based positioning in mind.
Here's my code for updating the physics. I'm using plain C# so I'm using Environment.Tickcount:
public int LastTick = Environment.TickCount;
public void Draw(object sender, EventArgs e)
/*Drawing code here*/
float delta = Convert.ToSingle(Environment.TickCount - LastTick) / 1000f;
LastTick = Environment.TickCount;
I don't know if it's a good idea to do it in the draw event. I don't see how that would affect it, though?
I've tried everything, and I don't know what to do about it.