Box+Circle character, slopes

Topics: User Forum
Mar 14, 2010 at 12:17 AM

Hello.

I'm still playing around with the engine in order to get a nice base for a 2D game. Right now I'm using the quite popular way of doing it:

Rectangle which is the upper body with a FixedAngleJoint, and a circle which is the feet. These are then connected with a RevoluteJoint (patched, Motor support), which I then use to move the character. Regarding the weight/mass I try to use some sort of real-life measurement i kilograms, the feet are 30f and body 30f.

The problem is when moving up by slopes. Either I can't go up them at all because of lacking power, or I can walk up by them, but then when I'm on the ground the feet start spinning way too much and the character starts bouncing around.

RevoluteJoint.Motor_Enabled = true;
RevoluteJoint.Motor_MaxTorque = 180f;
And when moving the Motor_Speed goes to +/- 50f.

Any tips? I don't mind if the player doesn't have super correct physics when moving, it's okay if there's some penalty and gain of speed when moving up and down slopes, but right now it's not working.

Mar 14, 2010 at 4:00 AM

Hi Glaucous

That sounds like either the Motor_MaxTorque is too low or the Circle's friction is too low. Try jumping them up to see if there's a difference

Mar 14, 2010 at 12:13 PM
Edited Mar 14, 2010 at 12:37 PM

I have the circle's friction at 1f (which is 100%, as far as I know), and when jumping the MaxTorque to 240 the circle/feet starts spinning way too much and the player starts bouncing. Too be honest I don't quite understand how the Motor_Speed works, how is it related to the MaxTorque?

 

Edit: Okay, now I set the friction to 1000f, which apparently made a huge difference, now the player can stand on slopes without gliding down, and I can run up by them. The former question about how Motor_Speed works still stands though.

Mar 14, 2010 at 12:59 PM

The Motor_MaxTorque is the maximum rotational force (torque) that the motor will use to achieve the desired speed (Motor_Speed).

Mar 14, 2010 at 1:48 PM
Edited Mar 14, 2010 at 2:32 PM

Ah, I see. And what is the "speed", LinearVelocity?

Edit: Well it's not LinearVelocity, which might make sense. Anyhow, got it all working now, this is looking good. :)

Mar 15, 2010 at 2:40 AM
Edited Mar 15, 2010 at 2:49 AM

It's the rotational velocity. I think thats how many radians it turns per second.

On a related subject, does somebody know how to calculate what rotational velocity is needed for a circle with radius r to move at a specified linear velocity?

EDIT: I think I've got it:
rotational velocity = linear velocity / radius of circle

It might not be that accurate in a physics engine especially if the friction is low and the wheel slips, but it might be a good guide on what speed to use.

Mar 16, 2010 at 11:13 PM

Yes, it seems to make sense.

I actually have another question while I'm at it; how do you create an object which has a constant force upwards? Such as a balloon or similar, the best way?

Mar 17, 2010 at 3:21 AM
Edited Mar 17, 2010 at 3:23 AM

Use the BouyancyController.

To have it only affect certain objects, you have 2 options:

  1. Modify it to only affect objects in a certain collision category
  2. Give the controller a real world density (real air has a density of 1.2 kg/m3). Then, if you make your bouyant objects as light as helium (0.1785 kg/m3) then they will float!

The problem with number 2 is that because bouyant objects are so much lighter in proportion to the other objects, they get thrown around at small collisions and there is a lot of unstableness if they get wedged between 2 normal objects.

In my game I use method 1, as well as making the object ignore gravity. That way I can tweak it to feel how I want.

EDIT: Also see this post http://farseerphysics.codeplex.com/Thread/View.aspx?ThreadId=46884