PhysX Tank Simulation in Unreal

Started by
19 comments, last by Fulcrum.013 5 years, 5 months ago

Hey, I've been playing around with making a tank in Unreal using PhysX. I have suspension working really well with some physics constraints, but I'm having a few issues with both the turning and the propulsion. I am aware that there's already an open source plugin that does this, but I've played around with it and it seems to be very performance intensive, so I've decided to roll my own solution.

The main problem I've had is turning the tank realistically, while the tank is in gear (neutral is no problem, as neutral steering is quite easy). From my understanding tanks use several methods to turn themselves. One is to brake on one side of the tank, while the other remains at full throttle. The other way is by using a gear differential, such that the tread on the inside of the turn is turning at a slower rate than the one on the outside. I'm not quite sure how to model the differential method using PhysX, and I've had issues with getting the braking method to work, ie. the tank spins out and the brakes don'y apply hard enough to keep the turning radius reasonable.

I was wondering if anyone could offer some tips or advice. My thought to fake it would be to apply some kind of radial force based off of an imaginary turning circle, but I'm not quite sure what the magnitude of that force should be, such that turns slow down the tank.

 

Cheers 

Advertisement
10 hours ago, BlueSpud said:

I was wondering if anyone could offer some tips or advice. My thought to fake it would be to apply some kind of radial force based off of an imaginary turning circle, but I'm not quite sure what the magnitude of that force should be, such that turns slow down the tank.

What helps maybe is to use utility functions to 'convert' linear and angular target velocities to force and torque, because it's easier to control stuff with velocity than with force. (I can look them up in my code if you want...)

You could also look at the tank simulation demo in the Newton physics engine: https://github.com/MADEAPPS/newton-dynamics/ (hope it's still there). This is a very detailed and complex demo thought as a stress test for joints (each unique part of the tracks is its own rigid body). PhysX can't do this, but i remember the developer had some headaches about turning too, so maybe there is some insight.

3 minutes ago, JoeJ said:

What helps maybe is to use utility functions to 'convert' linear and angular target velocities to force and torque, because it's easier to control stuff with velocity than with force. (I can look them up in my code if you want...)

I'm a little curious how you did that. I initially started using linear force, but opted against it. The reason being is that I'm using capsules for the wheels and applying torque to them to make them move. When they arent on the ground, they don't apply force. If I was to use linear force, AFAIK, I would have to do raycasts or sweeps for every wheel to determine if they were touching the ground or not and should be applying force.

 

I will definitely see if I can find the Newton demo though, hopefully theres something there.

6 minutes ago, BlueSpud said:

I'm a little curious how you did that. I initially started using linear force, but opted against it. The reason being is that I'm using capsules for the wheels and applying torque to them to make them move. When they arent on the ground, they don't apply force. If I was to use linear force, AFAIK, I would have to do raycasts or sweeps for every wheel to determine if they were touching the ground or not and should be applying force.

My suggestion is very basic. E.g. imagine a box on a ground without friction (ice), and you want to move it around in a circle. You would first calculate the linear and angular velocity you want, and second calculate force and torque from those velocities so the box moves as intended. I did not think about how to model tracks or ground contact and friction at all.

However, this gives me another idea: With Newton it is possible in a contact callback to modify the contact velocity. This way it's easy to do things like conveyor belts and tracked vehicles should work well also. I would assume UE exposes such functionality too?

 

7 minutes ago, JoeJ said:

My suggestion is very basic. E.g. imagine a box on a ground without friction (ice), and you want to move it around in a circle. You would first calculate the linear and angular velocity you want, and second calculate force and torque from those velocities so the box moves as intended. I did not think about how to model tracks or ground contact and friction at all.

However, this gives me another idea: With Newton it is possible in a contact callback to modify the contact velocity. This way it's easy to do things like conveyor belts and tracked vehicles should work well also. I would assume UE exposes such functionality too?

 

AFAIK, Unreal doesn't expose this. For their official tutorial on a conveyer, they just use a collision volume and move the objects manually, without going through the physics engine.

 

I think the problem is with the first method is that friciton is a lot of what makes the tank turn, so it has to be modeled rather well to get that working, which is another reason why I'm not trying to fight the engine and use as much of PhysX as I can without applying a lot of manual forces and such.

32 minutes ago, BlueSpud said:

I think the problem is with the first method is that friciton is a lot of what makes the tank turn, so it has to be modeled rather well to get that working, which is another reason why I'm not trying to fight the engine and use as much of PhysX as I can without applying a lot of manual forces and such.

I see - you aim for more realism. But i doubt UE does not expose contact velocity. This is necessary for other things like a raycast car, so maybe you can find an example about this (hoping vehicles are not locked up behind another abstraction). 

 

But i see two options: Faking contact velocity or controlling the whole tank yourself as i have proposed - to make it realistic you would need to run your own small simulation on top. You would still utilize PhysX for the harder things like collision response. And if you take care to conserve momentum - nothing wrong with that.

Or modeling the tracks itself or at least an approximization, probably with some form of wheels and suspension joints.

 

The latter can be a bit demanding, eventually requiring more physics iterations than usual (racing games often run at 300 Hz or more), and also it might be necessary to go deeper into the UE source if PhysX is only partially exposed. For example, IIRC PhysX has some Featherstone solver for joints (intended for ragdolls). This solver should be more expensive but may handle larger mass ratios and stiff joints. Worth to try and ask at UE forum as well...

Some personal experince of myself (i've made a physics driven walking ragdoll, no vehicles): In terms of robustness, accuracy and realism, nothing comes even close to Newton. The difference is orders of magnitude, while performance matches PhysX or Havok more or less. There is some effort to make a UE Newton plugin (see their forum), but UE is not designed to replace PhysX, so i don't know how practical this is.

The final option is to make your own joint solvers for a detailed vehicle model and apply resulting torques and forces to PhysX. That's how Natural Motion works on top of 3rd party engines for example.

 

So it's mainly a question of how much realism you really need, how much performance allows and how much time you can spend. No easy decision.

I hope you get some more answers from people with better vehicle experience.

 

 

2 minutes ago, JoeJ said:

I see - you aim for more realism. But i doubt UE does not expose contact velocity. This is necessary for other things like a raycast car, so maybe you can find an example about this (hoping vehicles are not locked up behind another abstraction). 

 

But i see two options: Faking contact velocity or controlling the whole tank yourself as i have proposed - to make it realistic you would need to run your own small simulation on top. You would still utilize PhysX for the harder things like collision response. And if you take care to conserve momentum - nothing wrong with that.

Or modeling the tracks itself or at least an approximization, probably with some form of wheels and suspension joints.

 

The latter can be a bit demanding, eventually requiring more physics iterations than usual (racing games often run at 300 Hz or more), and also it might be necessary to go deeper into the UE source if PhysX is only partially exposed. For example, IIRC PhysX has some Featherstone solver for joints (intended for ragdolls). This solver should be more expensive but may handle larger mass ratios and stiff joints. Worth to try and ask at UE forum as well...

Some personal experince of myself (i've made a physics driven walking ragdoll, no vehicles): In terms of robustness, accuracy and realism, nothing comes even close to Newton. The difference is orders of magnitude, while performance matches PhysX or Havok more or less. There is some effort to make a UE Newton plugin (see their forum), but UE is not designed to replace PhysX, so i don't know how practical this is.

The final option is to make your own joint solvers for a detailed vehicle model and apply resulting torques and forces to PhysX. That's how Natural Motion works on top of 3rd party engines for example.

 

So it's mainly a question of how much realism you really need, how much performance allows and how much time you can spend. No easy decision.

I hope you get some more answers from people with better vehicle experience.

 

 

Thanks for the suggestion. I'm not aiming for total realism, but I would prefer that it was somewhat realistic, the game I'm trying to make is not an arcade game. Ill definitely look into PhysX a little more, but I belive that if it did support those features, than someone would have already used them to make a similar project. 

 

Cheers :)

2 hours ago, BlueSpud said:

I think the problem is with the first method is that friciton is a lot of what makes the tank turn

Strictly it not just a friction. Each track have a chasers that  embedded to the ground, so it have much higher resistance to slide than just a friction. Also looks like it resistance is anisotropic.

#define if(a) if((a) && rand()%100)

Im not aware of physix etc but if one track produces bigger force and you apply that force to a pivot the tank will turn no matter what, what you could do is to define where to place pivots (where force is applied on each track) i think that will require more than one point per track, never tried to do realiatic tank sim though...

On 9/25/2018 at 7:53 PM, _WeirdCat_ said:

Im not aware of physix etc but if one track produces bigger force and you apply that force to a pivot the tank will turn no matter what, what you could do is to define where to place pivots (where force is applied on each track) i think that will require more than one point per track, never tried to do realiatic tank sim though...

I cranked up the friction (past 1.0) to simulate this, and while it did help, it certainly is not perfect.

This topic is closed to new replies.

Advertisement