Ball and box character wobble

Topics: Developer Forum
Jul 6, 2010 at 8:03 AM
Edited Jul 6, 2010 at 9:13 AM

I know there's a million posts on this, but bare with me.

I've got the basic set up down, got the guy (or girl) running nicely but as soon as I stop she wobbles. I know this is because of the ball used as her legs. I added the fixed angle joint just like RobertDodd suggested, but as soon as I try and clamp down the character still wobbles. I'll post some of my very messy code so you can take a look at it... Bare in mind that I've just redone the physics and this code is VERY rough until I get things working.



  if (mGameInput.WasLeftAnalogRight(mPlayer))
                pi.motor.Motor_Enabled = true;
                pi.brk.Enabled = false;

            if (mGameInput.WasLeftAnalogLeftReleased(mPlayer) || mGameInput.WasLeftAnalogRightReleased(mPlayer))
                pi.motor.Motor_Enabled = false;
                pi.brk.Enabled = true;
                pi.brk.TargetAngle = pi.legs.TotalRotation - pi.b.TotalRotation;


That's my input controls, basically, right analog, enable motor and walk right, if either has been released (naming convention is a bit rococo) enable the 'brk' (break) and set the target angle to the current ball rotation. pi.b is the rectangle body.


And this is how I set up the bodies and the geometry. = ps;
            pi.b = BodyFactory.Instance.CreateRectangleBody(ps, 90 * mScale, 230 * mScale, 10);
            FixedAngleJoint faj = JointFactory.Instance.CreateFixedAngleJoint(ps, pi.b);
            faj.BiasFactor = 1.2f;
            faj.MaxImpulse = float.PositiveInfinity;

            Vector2 generaloffset = new Vector2(0, 35 * mScale);

            Geom bodygeom = GeomFactory.Instance.CreateRectangleGeom(ps, pi.b, 90 * mScale, 230 * mScale, new Vector2(0, -110 * mScale)-generaloffset, 0, 0);
            bodygeom.CollisionCategories = CollisionCategory.Cat2;
            bodygeom.CollidesWith = CollisionCategory.All & ~CollisionCategory.Cat2;
            bodygeom.OnCollision += HandleBodyCollision;

            pi.legs = BodyFactory.Instance.CreateCircleBody(ps, 45*mScale, 1);
            Geom leggeom = GeomFactory.Instance.CreateCircleGeom(ps, pi.legs, 45*mScale, 36, -generaloffset, 0);
            leggeom.CollisionCategories = CollisionCategory.Cat2;
            leggeom.CollidesWith = CollisionCategory.All & ~CollisionCategory.Cat2;
            leggeom.FrictionCoefficient = 200.0f;
            leggeom.RestitutionCoefficient = 0.0f;

            pi.motor = JointFactory.Instance.CreateRevoluteJoint(ps, pi.b, pi.legs, -generaloffset);
            pi.motor.Motor_Enabled = false;
            pi.motor.Motor_MaxTorque = 60.0f;
            pi.motor.Motor_Speed = 5.0f;
            pi.motor.Softness = 0.9f;
            pi.motor.BiasFactor = 1.0f;

            pi.brk = JointFactory.Instance.CreateFixedAngleJoint(ps, pi.legs);
            pi.brk.BiasFactor = 1.0f;
            pi.brk.MaxImpulse = float.PositiveInfinity;
            pi.brk.Softness = 0.3f;


I think part of my problem is that I don't fully understand what the BiasFactor does or what it does to the joints. Is there something silly I'm doing here? Any values that are a bit strange? My gravity is currently set to 750 in the y.

I thought the problem might be that the box still carries momentum after the ball has stopped so causes a wobble as it places itself back where the joint wants it, but when I changed the players draw coordinates to the ball instead of the body the character flipped out and started flying in circles around the scene. The circle geometry looked like it had separated from the rectangle body and the character was able to defy gravity. But the only thing I changed was getting the body position to getting the circle position... Stepping through the code didn't help, everything looked as it should be.

Any help or comments would be greatly appreciated. :)


(PS. Robert Dodd, I didn't realise you made boxycraft! That game looks really good!)



I've played about some more and for some reason the circle acting as the legs goes bonkers if its mass is anywhere above 2... I can't seem to position it either or else it causes a nice NAN exception in the angular velocity. It seems strange that it bugs out while in mid air, I'd have thought it would need to collide with something first. I've made sure that the two bodies that make up the character aren't colliding with each other... But still things freak out. No idea what is wrong with these circles...

Jul 9, 2010 at 3:25 PM

So I gave up on that method of trying to get my character to walk properly, it was far too difficult. I've just scrapped another method using an circular body and trying to set an initial impulse and a constant force against the drag coefficient, and that method is horribly complicated with jumping and being able to climb. Especially when the drag slows how fast they fall and increasing gravity just brings me back to more problems moving horizontally.

Is there a good way to work out how much force I need to apply to reach a kind of terminal velocity? I understand the equation for drag used by the engine but haven't really found a relation to applying a constant force and receiving a constant speed. It would be really useful if there was a 'movebody' function that just allows the body to be moved without the need of a force. Obviously updating the position acts as a type of 'teleport' which means it's possible to teleport into other objects, so any move function should just move the body the specified amount without needing to apply impulse, force or teleporting it. It looks like a lot of people have tried making platformers with Farseer and suceeded, so I'm not sure why I'm finding it so difficult. If anyone has any code they could show me of things working I'd be really happy. I'm fed up of tweaking the same 100 values trying to get the characters to move in a sensible way.

I've also tried changing the velocity, but again that causes sliding, and it means that my characters can't be moved by physics (like getting thrown by objects) because I need to set the velocity back to zero. I also have problems where characters can stick to walls because of the friction being applied and the force pushing them into the wall. I solved this by changing the body friction to be below 0, but when apply force into the wall while in the air, I fly up it.

My group have got testers coming to play this game on Wednesday, so I really need to get the basic mechanics done by then, so any help anyone could give me is more than appreciated.