Issues applying torque to an object

Topics: User Forum
Jul 16, 2010 at 6:35 PM
Edited Jul 17, 2010 at 5:46 PM

I am part of a team at Dare to be Digital.

We are using Farseer Physics 2.1.3 in a game for the Windows Phone 7.

Everything is going well, but we seem to have run into a problem with applying Torque to an object.

What we are doing is creating a rotating windmill. The body and geometry are created from vertices, generated from a texture. Here is the code for it:

 

body = BodyFactory.Instance.CreatePolygonBody(vertices, 1f); // vertices generate from texture

body.Position = this.position;

origin = vertices.GetCentroid();

geom = GeomFactory.Instance.CreatePolygonGeom(body, vertices, 0);

JointFactory.Instance.CreateFixedRevoluteJoint(simulator, body, body.Position + origin);

simulator.Add(body); simulator.Add(geom);

 

Here is what we have in the update:

body.ApplyTorque(150f);

We have tried this with different combinations of torque and RotationalDragCoefficient but that doesn't seem to affect it at all, even if we apply no torque. We also tried directly changing the body.Rotation value, that didn't work either.

The only thing that does happen is that it turns ~180 degrees CW and then CCW and doesn't stop or change pace. It's been a problem that has been baffling us for a while.

 

Thanks in advance for any suggestions.

Jul 17, 2010 at 5:57 PM

I just managed to clean some of the text up so it is more readable. Sorry about the previous mess!

Jul 18, 2010 at 1:22 PM
Edited Jul 18, 2010 at 1:30 PM
I am guessing that the ~180 degrees CW and then CCW is because it is working like a pendulum.
Try moving the set origin first, and remove the addition of the origin from the CreateFixedRevoluteJoint method.

Example:

origin = vertices.GetCentroid();

body = BodyFactory.Instance.CreatePolygonBody(vertices, 1f); // vertices generate from texture

body.Position = this.position;

geom = GeomFactory.Instance.CreatePolygonGeom(body, vertices, 0);

JointFactory.Instance.CreateFixedRevoluteJoint(simulator, body, body.Position);

simulator.Add(body); simulator.Add(geom);
Jul 18, 2010 at 10:44 PM

Thanks a lot for the reply.

I think I recall trying that before and that may not have worked properly, but since I can't remember exactly I will give it a go when I am at the office tomorrow.

I will let you know how it goes.

Thanks for the suggestion.

 

The other thing that my team thought of was maybe not using a Joint at all and set the same position every Update.

 

Jul 19, 2010 at 1:40 PM
Edited Jul 19, 2010 at 1:40 PM

Just a comment to my earlier post.

Moving the origin = vertices.GetCentroid(); doesn't matter (You had it correct in the first place),  as long as it is before the GeomFactory.Instance.CreatePolygonGeom(body, vertices, 0); 

CreatePolygonGeom will translate the vertices, so getting  the origin from the vertices before this is a good idea.