Page 1 of 1

Tank physics

Posted: Tue May 14, 2013 12:23 pm
by kavatortank
Hello,
At first, please excuse my English because I'm French. I actuelement engineering school. During this year I make a computer project. So I choose to make a 3D tank game in XNA / C #. But after one month, I regret my management of physics. That's why I looked for a physics engine, and I found bepuphysics.
I looked at the sample engine, which does not suit me at all, because I think the management of tank unrealistic. After much testing I got was something quite realistic.
So I have several problems:
- My tank can climb very steep hills.
- I want to put a turret on the tank, but I do not know how. I first with compoundBody, but I can not seem to perform transformations on its compondBody. So I decided to make joints between the turret and the tank, but the result is not as expected. For the turret when it collides, makes strange movement.

Thank you in advance for your answers.

Re: Tank physics

Posted: Wed May 15, 2013 12:29 am
by Norbo
- My tank can climb very steep hills.
If you are using the Vehicle class, the grip strength is probably too high, or perhaps the maximum drive impulse.

I should note that, while I did create a tank-like example, the Vehicle isn't really entirely appropriate for creating tread-like control. You may find that it's easier to fine tune the control if you just use the Vehicle wheels for support, and then implement your own sliding friction and drive mechanism. It may not be quite as robust as the vehicle's solver-based friction, but such accuracy may not be needed.
I want to put a turret on the tank, but I do not know how. I first with compoundBody, but I can not seem to perform transformations on its compondBody.
Compound bodies are indeed made to be entirely rigid and immutable. Changing them generally requires reconstructing them (with a few exceptions).
So I decided to make joints between the turret and the tank, but the result is not as expected. For the turret when it collides, makes strange movement.
Could you create an example turret joint setup in a BEPUphysicsDemos demo so I can check it out?

Re: Tank physics

Posted: Wed May 15, 2013 5:53 am
by kavatortank
Ok so i did some pictures.
The first is to represent when my tank can climb very steep hills.
http://imageshack.us/photo/my-images/34 ... ction.png/

The second is to represent my bad connection
http://imageshack.us/photo/my-images/84 ... oints.png/

because a turret in a real tank can do this XD

And I join my file tankInput.cs so you just have to include it to the samples


EDIT :

Thanks for your help :)

Re: Tank physics

Posted: Wed May 15, 2013 9:19 pm
by Norbo
The first is to represent when my tank can climb very steep hills.
This appears to just be excessive grip/drive strength, as mentioned. You could think of it like this: right now, the largest impediment to the tank's movement is its own mass and friction. Once it has sufficient strength to overcome those barriers, trivial things like 'cliffs' are no longer an issue :)

It can be hard to tune tanks properly because of all the competing constraints, but a starting point would be to reduce the maximum drive force. You'd probably need to also reduce the rolling friction as well to let it move more freely.

This will probably further necessitate changes to the turning variables since the lowered drive force probably won't be enough to overcome sliding friction. You may find that reducing the sliding friction strategically while attempting turns makes things easier.
The second is to represent my bad connection
http://imageshack.us/photo/my-images/84 ... oints.png/

because a turret in a real tank can do this XD
I'm not sure what that represents; is the tank ramming the turret into the wall? In that case, a bit of joint error is expected. There are two reasons for this:

1) The tank and its turret are heavy relative to the default constraint configurations. Constraints can be thought of as springs with some default damping and stiffness. Larger forces will be able to pull further on the spring.

You can see the difference by either reducing the mass of the tank and turret, or by increasing the rigidity of the springs. For example, to increase a revolute joint's BallSocketJoint rigidity:

Code: Select all

axisJoint.BallSocketJoint.SpringSettings.DampingConstant *= 3;
axisJoint.BallSocketJoint.SpringSettings.StiffnessConstant *= 3;
Note that having some softness to the springs is helpful for stability.

2) The tank body itself is much heavier than the turret- a factor of 500 for the barrel, and 100 for the turret body- so it will have a hard time propagating the full stopping impulse to the tank. This is related to the 'mass ratio' problem: if a very heavy object depends on a light object in a constraint system, stability will suffer. You can also see this when the tank runs into light boxes on the terrain and causes them to squish. (A light object that depends on a heavy object, on the other hand, is perfectly fine.)

It is a good idea in general to keep mass ratios relatively tight. For most interactions, keeping things within a factor of 10 would be good. For a tank specifically, you may find that you don't care that it crushes other objects- after all, crushing things is rather tanklike- so the mass ratio could be larger.

(Mass ratio issues in collisions are handled quite a bit more gracefully in the latest versions, so it may be worth upgrading.)

Other than that, the tank turret seems to behave pretty much as expected within the latest version of the BEPUphysicsDemos.

Re: Tank physics

Posted: Wed May 15, 2013 10:53 pm
by kavatortank
Norbo wrote: This will probably further necessitate changes to the turning variables since the lowered drive force probably won't be enough to overcome sliding friction. You may find that reducing the sliding friction strategically while attempting turns makes things easier.
Okay for this, so it's very hard to seek thoses values and to have realistics tank mouvement
Norbo wrote: 1) The tank and its turret are heavy relative to the default constraint configurations. Constraints can be thought of as springs with some default damping and stiffness. Larger forces will be able to pull further on the spring.

You can see the difference by either reducing the mass of the tank and turret, or by increasing the rigidity of the springs. For example, to increase a revolute joint's BallSocketJoint rigidity:

Code: Select all

axisJoint.BallSocketJoint.SpringSettings.DampingConstant *= 3;
axisJoint.BallSocketJoint.SpringSettings.StiffnessConstant *= 3;
Note that having some softness to the springs is helpful for stability.

2) The tank body itself is much heavier than the turret- a factor of 500 for the barrel, and 100 for the turret body- so it will have a hard time propagating the full stopping impulse to the tank. This is related to the 'mass ratio' problem: if a very heavy object depends on a light object in a constraint system, stability will suffer. You can also see this when the tank runs into light boxes on the terrain and causes them to squish. (A light object that depends on a heavy object, on the other hand, is perfectly fine.)

It is a good idea in general to keep mass ratios relatively tight. For most interactions, keeping things within a factor of 10 would be good. For a tank specifically, you may find that you don't care that it crushes other objects- after all, crushing things is rather tanklike- so the mass ratio could be larger.

(Mass ratio issues in collisions are handled quite a bit more gracefully in the latest versions, so it may be worth upgrading.)
I understand thoses solutions but in reality, the turret of a tank is FIX, so it cannot move in anydirection ( exepct rotation on the free axis ).
Norbo wrote: Other than that, the tank turret seems to behave pretty much as expected within the latest version of the BEPUphysicsDemos.
And i don't understand this sentence, can you developpe ?

Re: Tank physics

Posted: Wed May 15, 2013 11:16 pm
by Norbo
Okay for this, so it's very hard to seek thoses values and to have realistics tank mouvement
Yes, indeed it is; the Vehicle is designed for wheeled vehicles like a regular car, not a tank, so getting things fine tuned is far from easy.

I would recommend keeping my previous suggestion in mind should it prove too hard to achieve the desired behavior through tuning:
You may find that it's easier to fine tune the control if you just use the Vehicle wheels for support, and then implement your own sliding friction and drive mechanism. It may not be quite as robust as the vehicle's solver-based friction, but such accuracy may not be needed.
I understand thoses solutions but in reality, the turret of a tank is FIX, so it cannot move in anydirection ( exepct rotation on the free axis ).
Addressing the spring strength and mass ratios can make it substantially more rigid. However, even a real tank will have problems if it rams its turret into a steel wall :)
And i don't understand this sentence, can you developpe ?
By that sentence, I just mean I didn't notice any other obvious issues while playing around with it, with the caveat that I was using the latest version of BEPUphysics. If you're using a different (older) version, you may see some behavior that I do not see in the newer version. The dll-only download is quite a bit outdated compared to the latest source.

Re: Tank physics

Posted: Thu May 16, 2013 12:12 am
by kavatortank

Code: Select all

BallSocketJoint.SpringSettings.DampingConstant *= 3000;
BallSocketJoint.SpringSettings.StiffnessConstant *= 3000;
This works great ^^, it is a good solution ?

Re: Tank physics

Posted: Thu May 16, 2013 12:17 am
by Norbo
Given that the mass is about a thousand times higher than the standard range, it makes sense that it would take around a thousand times higher rigidity to accomplish a similar feel, so that is reasonable. If you end up reducing/tuning mass to stop mass ratio related issues later, you may want to reduce/tune the spring rigidity proportionally.

Re: Tank physics

Posted: Thu May 16, 2013 12:49 pm
by kavatortank
Ok, thanks a lot men ;)

I'm going to do what you say to me.