This project is read-only.

Problem adding Forces to a Body

Mar 31, 2008 at 4:57 AM
I'm playing around with the JigLibGame, and I've created a BoxObject in a scene. I'm trying to add forces to the box body when I press certain keys, and I am adding forces using body.AddWorldForce() and AddWorldTorque(). This is where I am having the problem: the box starts off from some height above my terrain, so it will fall and bounce a bit at the start of the program. If I press my input keys to apply the forces while it's still moving, it works, and the box will turn and move appropriately. However, if I let the box comes to a complete stop, no matter how much force I apply to the box using the methods, the box will not move.

I have no idea if I'm missing something or if this is a bug or not.

Here's a summary of what I did in the code for more information:
I've extended a class from Body and overwritten AddExternalForces method as it will call the method to calculate the forces I apply to the box when I press the keys.

public override void AddExternalForces(float dt)



Inside my Box object I basically added a AddExteranlForce method that will calculate the forces applied to the box. It looks something like this, edited:
public void AddExternalForces(float dt)
body.AddWorldForce(Vector3.Transform(new Vector3(acceleration * 100, 0, 0), body.Orientation));
body.AddWorldTorque(new Vector3(0, turning, 0));

acceleration and turning are changed depending on the input and are set to 0 when there's no input.

Any feedbacks will be appreciated, thanks!
Apr 1, 2008 at 4:04 AM
I've tried to understand the problem and I don't know how to fix it. I tried to set the physic body to active but it didn't work. I don't what use you are going to do with the force but if you want you can use velocity. It works fine for me.

I hope it helps.
Apr 1, 2008 at 6:44 AM
I need to be able to apply an up force to the corners of the box. Making changes to the velocity won't allow me to apply it to a certain area of the box. This is a weird problem, wondering if it is a bug.

Thanks for your input though!
Apr 1, 2008 at 8:19 AM
Don't get stuck to a problem like that. If I understand wheel you are trying to do a vehicle between an car and plane? Why don't put some box in the corner ( the place for wheel) and apply velocity to each of them? I'm not pretty sure that the force react differently than velocity ( except the time factor). Use different boxes and add some constraint distance to them to simulate the suspension ( on the air for you). Unless you are trying to do a car simulation you should try some tricky ways to achieve your goals. I'm worked on newton and even if a great engine it's not suited to all our needs, so I had to try a lot to achieve a simple kart behaviour.