This project has moved and is read-only. For the latest updates, please go here.

Strange behavior ...

Topics: User Forum
Nov 20, 2006 at 11:36 PM
Firstly, great physics engine ...

Secondly, sorry if this is a thick question ...

I am trying to use your physics stuff to allow my character to walk around a maze. The player is defined as a circle and my walls are defined as a simple set of rectangles (each occupying one square on a 10x10 grid). I just want the player to slide along the walls.

Walls are defined as -

.FrictionCoefficient = .0f;
.RotationalDragCoefficient = .0f;
.LinearDragCoefficient = .0f;
.RestitutionCoefficient = .0f;
.IsStatic = true;

The player is defined as -

Player = new CircleRigidBody(16, 24, 1);
Player.RotationalDragCoefficient = .0f;
Player.LinearDragCoefficient = .5f;
Player.FrictionCoefficient = .0f;
Player.RestitutionCoefficient = .0f;

The players position is updated -

CircleRigidBody g = cPhysics.Player;

g.Orientation += GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X / 16;

Vector2 v = new Vector2(0, GamePad.GetState

v = Vector2.Transform(v, -g.BodyRotationMatrix);


This kind of works, but it isnt perfect. The player receives some spin and doesnt behave as expected with the walls, can anyone suggest a way of making this work better please ?

Thanks guys,
Nov 21, 2006 at 3:08 AM
First, glad you like the engine.

One problem I see is this:

g.Orientation += GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X / 16;

The orientation of a body should not be updated explicitly every frame. It should be set at the begining then driven by the physics engine by applying torques.

So, instead of rotating the object by setting the orientation explicitly, apply positive and negative torques (rotational forces) instead.

When you first start trying to do this it may feel sloppy because the body will over rotate and be hard to control. When this happens, try increasing the RotationalDrag on the body until you get the "feel" you want.

Let me know if you still have issues with this.

Nov 21, 2006 at 3:20 AM
Here is some code from an old test project that may give you some ideas.

public void Thrust() {
//get the forward vector
Vector2 thrust = new Vector2(-rigidBody.BodyMatrix.Up.X, -rigidBody.BodyMatrix.Up.Y);
thrust *= thrustMagnitude;
rigidBody.ApplyForceAtLocalPoint(thrust, new Vector2(0, 0));

public void TurnLeft() {

public void TurnRight() {

public void ApplyTorque(float torque) {
Nov 21, 2006 at 9:51 AM
Thanks for the help and code ... right I think we are getting there. I have used your code (thanks), but it still feels too 'floaty'. Is there a way of clearing all torque from an object (if the player isnt turning). I have tried increasing the rotation drag but it doesnt cure it, it just helps. I have also tried the cleartorque but it doesnt seem to do it either.

FYI - I am trying to use this as a collision detection system for a first person game. A 2D map is used to plot the progress of the player, it just needs to feel like a player walking in any FPS rather than a space ship using thrust (which it mimicks excellently (c:).

any advice is very much appreciated, thanks again.

Nov 21, 2006 at 1:09 PM
The engine clears the torque every loop by itself.

You should be able to get a fps feel by just applying torques and setting the RotationalDrag correctly. Granted, I've never tried to tweak the parameters for that kind of affect but it should be possible.

It's really the only way I can think to do it without intefering with the physics engine's simulation...
Nov 21, 2006 at 1:27 PM
it is working and I am walking around my map, it just doesnt feel correct and it makes you feel a little ill after a while (you get into a rhythmic wave and you are constantly adjusting your direction).

I will have another play with it tonight and see if I can make it work.

thanks again.

PS If you have any other ideas or can suggest settings, it would make my life easier. Also, can you explain in absolute beginners terms the difference between torque and force :O)
Nov 21, 2006 at 2:11 PM
Torque is a rotational Force. Think of a wheel in space, applying torque will turn the wheel round and round, but the wheel will not move (unless we have friction which will then move the object). Force will "Push" an object, if we use the same wheel and apply force, it wheel will move in the direction of the force, but will not turn (unless their is friction).

Hope this helps.

Nov 21, 2006 at 9:45 PM
To get the feel you want, you will probably need to make both your torque factor and RotationalDrag fairly high.

With the drag high enough, it should not continue to turn once you stop applying torque.

Just try a bunch of different values.
Nov 21, 2006 at 11:25 PM
the turning is good now with these settings and it has fixed some of the issues with sliding down the walls -

RotationalDragCoefficient = 1945f;
cPhysics.ApplyTorque(GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X * 512);

I have got to the bottom of my issue. Sometimes when I 'walk' in a particular direction the path my object takes is not quite right (according to the angle its being drawn at), it looks to be off slightly (either a steeper or shallower angle). Also I can walk in a straight line and not apply any torque or hit anything and my object starts to turn on its own, any ideas ?

There is a small movie here, in the movie I dont apply any turn just forward motion, as you can see the player is turning to the left in an arc -

Nov 22, 2006 at 3:17 AM
Are you applying the force at the center of gravity for the object and not accidently at some offset?

I'm not really sure why it would do that.

Nov 22, 2006 at 10:15 AM
I am at work so cant remember exactly ...

I was using ApplyForceAtLocalPoint(force, new vector2(0,0)) but changed it to just ApplyForce(force)

I think thats right, I dont have the code in front of me.

It would appear (from a lamer) that the arc is being caused by a small amount of torque, but if it gets reset every update and I dont apply any, where is it coming from ? weird.
Nov 22, 2006 at 1:06 PM
When you created the geometry verts for your model, did you create it with the center at 0,0 ?

If not, then your object may be sort of lop-sided and applying the force at 0,0 (Which ApplyForce() does by default) is actually applying the force at some point other then the center of mass of the object.

When you create your geomety vertices, always do so as if 0,0 is you center of mass. Then, once the geometry/rigid body is created, you can move it where ever you want.

Nov 22, 2006 at 8:35 PM
I am just using the built in square and circle at the moment. So its using whatever the default is.

Nov 24, 2006 at 9:20 AM
I dont know if you have the time ... but could you mock up a 2 minute application just moving a circle around where it doesnt slide and arc like mine ? You dont have to include any walls or anything, just the walking around. I am having no luck at this end. I will understand if you dont have the time.

Nov 26, 2006 at 11:38 PM
I will try to get something up next week. I'm just back from thanksgiving vacation so don't have the time right now.
Nov 27, 2006 at 8:01 PM
Awesome, thankyou so much. I look forward to your update.

Thanks again,
Dec 1, 2006 at 12:49 PM
Sorry I haven't got this yet. Been busy this week. Hopefully I can get to it soon.
Dec 1, 2006 at 3:45 PM
No problem, I have been stoooopid busy myself. I really would like to see if this is possible as I have a nice idea for a game and the XNA toolkit 1 is coming soon .... december should be a month to remember.

Dec 11, 2006 at 12:25 PM
Hi, is it worth me trying the latest build to fix the issue I was having ?

Dec 11, 2006 at 5:25 PM
I don't think anything I did would address your issue, but you can try.

I'll try to get to your issue soon.
May 14, 2007 at 5:23 AM
Edited May 14, 2007 at 5:26 AM
same issue here:

When ApplyForce or ApplyForceAtLocalPoint are used on an object (CircleRigidBody) the object arcs away from it's expected destination.
Deviation increases over distance, and looks to be worse with forces containing larger absolute X values.


Quick Fix:
physicsObject.LinearDragCoefficient = 0.0f;

May 14, 2007 at 9:24 PM
Hmmm, sounds like maybe I'm not applying my linear drag correctly. It should always be applied opposite the bodies current motion.