Modeling a tank

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
goldsword
Posts: 18
Joined: Fri Dec 05, 2008 8:46 pm

Modeling a tank

Post by goldsword »

How would one go about modeling a tank effectively using BEPU, in my current but somewhat akward method I create 3 bodies (boxes), one for the body, turret and gun barrel. I make the body a dynamic object while the turret and barrel are simple static. All 3 bodies are told to not collide against any of the other three and every frame in the Tank.Update() I manually set the positions of the barrel and turret to match the tanks current orientation and world position. The problems I have with this setup is moving the tank, I'm using applyLinearImpulse but the tank will require alot of impulse units before being set into motion, I also have to control the max velocity each frame, constraining the XZ velocity to a certain magnitude while preserving the horizontal velocity. Using large weights for the tank is also a problem, since a modern tank weigh about 50.000 tons, in my simulation I have to set the tank to weigh about 500 kg instead, otherwise applying impulse will not result in any motion until very very high values and once that value is reached the frame rate will drop to 10 for some time and then the tank will recieve an incridible speed. So my basic questions are:

1. How would one setup the parts that make up the tank in an effecient and easy way, or am I using the corect method?

2. Is there a better way to control a bodies motion while still getting correct collision response, i.e. move() does exactly what I want except the collision response will not be performed. applyLinearImpulse is not very intuitive and I really cant seem to convert the expression move(Forward * X) into applyLinearImpulse(Forward * X * ConversionFactor). Im not that into physics but from what I can tell impulse should allow me to change the momentum of an object, momentum being mass * velocity, shouldnt I be able to apply an impulse that would result in a requested speed if I know the mass of my object?

3. Would it be better to use constraints to attach the turret and barrel over my manual method, although I guess this would mean I would have to make both the
turret and barrel dynamic objects.

Thankful for any advice on this subject.
User avatar
Zukarakox
Not a Site Admin
Posts: 426
Joined: Mon Jul 10, 2006 4:28 am

Re: Modeling a tank

Post by Zukarakox »

1. You can create a tank using the compoundbody class. It takes in entities and essentially makes them the same object while still applying physics to every entity inside.

This may not be quite right, I didn't check the syntax.

Code: Select all

CompoundBody tank;
List<Entity> parts = new List<Entity>();
parts.add(new Box(constructors));
parts.add(new Box(constructors));
parts.add(new box(constructors));
tank = new CompoundBody(parts);
space.add(tank);
Also, make sure all the parts you are using for the tank are dynamic, not static. Compound bodies only use dynamic entities.

2. Moving it would best be performed by tank.applyImpulse, Im not sure on the exact method but it should work. Also, you may want to lower the mass of the tank to something around 50, just to keep it inside a managable range. 500 isn't too bad, but theres no need to make everything higher than it has to be.

3. See 1.
i has multiple toes
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Modeling a tank

Post by Norbo »

If you want the tank to reach a specified velocity or momentum instantly, you can also use the entity.linearVelocity, entity.angularVelocity, entity.linearMomentum, entity.angularMomentum.

And as I think I mentioned before, a Vehicle with lots of wheels for treads could also be used to more directly simulate a tank.
goldsword
Posts: 18
Joined: Fri Dec 05, 2008 8:46 pm

Re: Modeling a tank

Post by goldsword »

Thanks for the replies, I think I'll go with the wheel based design together with compund objects. In general if you want "heavy" objects, is it better to use higher frictions over large masses? I like to work in SI units, meters, kg etc so my player is 75 kg, a wooden box is 10 kg but I guess putting a mass of 50.000 kg would cause instabilities?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Modeling a tank

Post by Norbo »

The primary reason you want to avoid giant masses (or more accurately, giant differences in masses between your simulation's entities) is that if your big heavy thing needs to be pushed back against by a light thing, it probably won't be able to. Imagine if the tank ran over a light box. The box wouldn't stay rigid, but instead squeeze out or look a bit weird in the process. Similarly, if you rammed an object of significantly less mass into a wall, there's a chance the tank would just shove it through the geometry since it will be hard for the light object to maintain its rigidity. Increasing the iteration count (space.simulationSettings.iterations) can help to a degree with this problem, but high iteration counts can harm performance.

Friction would be useful for preventing sliding when being impacted by smaller objects. Scaling the inertia tensor as well would prevent smaller torques from causing a spin, which may be desirable.
Post Reply