PDA

View Full Version : Help with torque



Sallen
05-05-2007, 11:24 AM
How do you use the AddForceAndTorque(Vector2 vForce, Vector2 vTorque) function? I've tried to pass various values as vTorque, but they don't seem to make the object turn.

Seth
05-06-2007, 12:31 PM
Hmm, good question. I think maybe it uses the X and ignores the Y, it doesn't make sense why it would take a vector instead of a number, but the physics code did it this way and I just copied it. I keep meaning to go check it out.

I'm thinking the best way I can debug/document it is make a little example, like a top down tank game that uses one sprite animation with 360 degree rotation.

Also, not sure if you noticed, but you can use Entity:SetRotation and Entity:GetRotation to directly set/read it, if that works as a work around for now. (like, if the left key is held down, you could use these to rotate left in 5 degree increments or something)

Sallen
05-06-2007, 03:53 PM
Well, as a matter of fact that is the workaround I'm using right now. I am trying to make a car game and I thought using torque instead of direct SetRotation() would make it appear more realistic when having collision against other objects (cars, walls, etc...).

Anyway, I'd like to ask for something else. I use AddForce() for acceleration, but when the car turns after having accelerated, it keeps sliding in the same direction, as if the tires of the car didn't grip to the ground, like a spaceship in space or a car on ice, until you accelerate again (applying a new AddForce() in the new direction).

How can I make the car turn when turning the wheels while it has inertia?

I'm sorry if I don't make myself understandable, but I'm not a native English speaker :o

Seth
05-07-2007, 09:54 AM
Ah, I think I know what you mean.. here is a hacky test, I think it does what you want.

I will be adding some features to make this easier to do... Needing to convert from a radian angle to a vector all the time is a bit messy.

Sallen
05-07-2007, 12:20 PM
I've looked into the tank example code, but I think its not what I mean.

I want the car to skid a little bit when turning, as if the inertia force kept pushing the back of the car in the old direction.

Attached is a crappy graphical explanation of what I mean.

Sallen
05-07-2007, 12:46 PM
I think I can tweak the tank's code so I get what I want, time will tell.

Thank you :)