🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

PhysX Tank Simulation in Unreal

Started by
19 comments, last by Fulcrum.013 5 years, 8 months ago
21 minutes ago, BlueSpud said:

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

really it much higher then 1. and also anithoropic and depends from ground hardness. for example on paving stoe and e.t.c where chassers can not be embedded to the ground it close to just a friction, but  on sand and humus it drive a ground  together with tracks so depenf from grounf viscosity and so on. also it anithotrophic depent of tracks relief, kind of sliding (rotation, forward/backward or left/right) and depth on wich tracks embedded to ground. 

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

Advertisement

Usually you can adjust contact tangents and binormal directions and adjust friction for each of them to model the anisotropy Fulcrum mentions (I can imagine this affects agility a lot: Better grip, better turning.)

That may be another feature that is not exposed, but such things do not cost extra performance, just some work on the interface, so i wonder about it.

... yep, there ist it, all the things i've mentioned should be there: https://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/guide/Manual/AdvancedCollisionDetection.html

On 9/29/2018 at 2:28 AM, JoeJ said:

Usually you can adjust contact tangents and binormal directions and adjust friction for each of them to model the anisotropy Fulcrum mentions (I can imagine this affects agility a lot: Better grip, better turning.)

That may be another feature that is not exposed, but such things do not cost extra performance, just some work on the interface, so i wonder about it.

... yep, there ist it, all the things i've mentioned should be there: https://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/guide/Manual/AdvancedCollisionDetection.html

That's an awesome resource, but as far as I can tell, that functionality requires an engine modification in order to get it to work. I think there has to be something other than the anisotropy that's tripping me up here.

AFAIK there is no rolling friction in PhysX. Right now I have my wheels as capsules, so friction serves as the anisotropic force. I have it cranked and it does seem to mitigate the drifting, but doesn't seem to make a realistic effect, and doesn't stop the sliding. I believe modern tanks use some kind of differential, but like I stated in the OP, I have no idea how to achieve this in the engine.

Take a look at tires, those are metal parts for simplification define that its made if lets say 18 parts and only maximum of 8 parts can contact the surface, now define a friction const and apply a force for each metal part of each track

2 hours ago, _WeirdCat_ said:

Take a look at tires, those are metal parts for simplification define that its made if lets say 18 parts and only maximum of 8 parts can contact the surface, now define a friction const and apply a force for each metal part of each track

Are you talking about using little rigid bodies that are adjacent to the wheels that would simulate friction? Using capsules as the collision mesh for the tires creates friction that opposes the tank sliding, which is really nice. But I'm still having a lot of issue making the thing turn in a believable manner.

 

I think the best option is to simplify this a lot, do the calculations to convert the torque that I would be applying to the wheels to a forward force and then make turning a torque on the hull of the tank, rather than rely on the physics engine to make the torque from the differential. And at least this way I will have much finer control over all of the forces and torques that are being applied, as opposed to being at the whim of PhysX

Well not actually, you just apply friction force of each metal object (were not now talking about collision model), you treat tank along with chasiss as one rigid body and apply rotational force on center of each surface/( metal tire part ) contact surface (torque) and you apply same to the center of mass cause you want to move the object.

However you need a damping function

To deal with NaN and imprecision

 


//needed to be fixed  if is nan
inline void damp( vec3 * ptr, float amount, float epsilon)
{
	(*ptr) = (*ptr) - (*ptr)/amount;
	vec3 p = vec3(absnf<float>((*ptr).x),absnf<float>((*ptr).y),absnf<float>((*ptr).z));
	if (IsNan(p.x)) p.x = 0.0;
	if (IsNan(p.y)) p.y = 0.0;
	if (IsNan(p.z)) p.z = 0.0;

	if ( (p.x > 0) && (p.x < epsilon) ) (*ptr).x = 0.0;
	if ( (p.y > 0) && (p.y < epsilon) ) (*ptr).y = 0.0;
	if ( (p.z > 0) && (p.z < epsilon) ) (*ptr).z = 0.0;
}



inline void damp( float * ptr, float amount, float epsilon)
{
	(*ptr) = (*ptr) - (*ptr)/amount;
	if (IsNan((*ptr))) (*ptr) = 0.0;
	if ( (absnf<float>(*ptr) > 0) && (absnf<float>(*ptr) < epsilon) ) (*ptr) = 0.0;
}

template <class type> bool IsNan (type f) { return (f != f); }

Using too little timesteps will crack the sim so you deal with it


	damp(&vel, 10.0, 0.007);
	damp(&AngVel, 10.0, 0.0005);

call that each frame before calculating new velocities/forces
  
  damp here is really simplified, didnt have time to spend on figuring how forces react on each other (in my case skin and body drag etc for rotations) so damp damps each x by x/10.0 in this case aecond parameter tells when were close to zero so we actually 0 it so theres no crack

If need any more help like explaining how you apply everything just reply

1 hour ago, BlueSpud said:

rather than rely on the physics engine to make the torque from the differential

Differential deliver same torque to both wheels. It just make a wheels angular speed independend. For each trackchain torque regulated by  friction clutch of driving wheel that limit maximal torque that can be delivered.

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

1 hour ago, BlueSpud said:

Using capsules as the collision mesh for the tires creates friction that opposes the tank sliding, which is really nice

For first approach assume that tracks have enought slide resistance to not slide forward-backward and deliver all applied force back to driving wheel axis.

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

On 10/5/2018 at 2:35 PM, _WeirdCat_ said:

Well not actually, you just apply friction force of each metal object (were not now talking about collision model), you treat tank along with chasiss as one rigid body and apply rotational force on center of each surface/( metal tire part ) contact surface (torque) and you apply same to the center of mass cause you want to move the object.

However you need a damping function

To deal with NaN and imprecision

 



//needed to be fixed  if is nan
inline void damp( vec3 * ptr, float amount, float epsilon)
{
	(*ptr) = (*ptr) - (*ptr)/amount;
	vec3 p = vec3(absnf<float>((*ptr).x),absnf<float>((*ptr).y),absnf<float>((*ptr).z));
	if (IsNan(p.x)) p.x = 0.0;
	if (IsNan(p.y)) p.y = 0.0;
	if (IsNan(p.z)) p.z = 0.0;

	if ( (p.x > 0) && (p.x < epsilon) ) (*ptr).x = 0.0;
	if ( (p.y > 0) && (p.y < epsilon) ) (*ptr).y = 0.0;
	if ( (p.z > 0) && (p.z < epsilon) ) (*ptr).z = 0.0;
}



inline void damp( float * ptr, float amount, float epsilon)
{
	(*ptr) = (*ptr) - (*ptr)/amount;
	if (IsNan((*ptr))) (*ptr) = 0.0;
	if ( (absnf<float>(*ptr) > 0) && (absnf<float>(*ptr) < epsilon) ) (*ptr) = 0.0;
}

template <class type> bool IsNan (type f) { return (f != f); }

Using too little timesteps will crack the sim so you deal with it



	damp(&vel, 10.0, 0.007);
	damp(&AngVel, 10.0, 0.0005);

call that each frame before calculating new velocities/forces
  
  damp here is really simplified, didnt have time to spend on figuring how forces react on each other (in my case skin and body drag etc for rotations) so damp damps each x by x/10.0 in this case aecond parameter tells when were close to zero so we actually 0 it so theres no crack

If need any more help like explaining how you apply everything just reply

I believe dampening is definitely not the way to go. In circular motion, the motion is not damped to keep the object on the correct path of motion.

On 10/5/2018 at 2:40 PM, Fulcrum.013 said:

Differential deliver same torque to both wheels. It just make a wheels angular speed independend. For each trackchain torque regulated by  friction clutch of driving wheel that limit maximal torque that can be delivered.

I was correct, tanks use a double/triple differential to vary the torque on each tread (see https://en.wikipedia.org/wiki/Differential_steering). The older ones use clutch breaking, which is non-regenerative, which is not currently what Im trying to accomplish.

 

I've been playing around with applying a torque manually to the entire hull of the tank in the z axis in addition to applying a different torque to each set of wheels, which has given me the motion that I desire. However, I'm still having a lot of trouble with sliding and achieving circular motion when the turn button is held down.

2 hours ago, BlueSpud said:

The older ones use clutch breaking, which is non-regenerative, which is not currently what Im trying to accomplish.

Im dont mean a clutch breaking. I mean transmission/stearing schemes that modern tank uses.

 

2 hours ago, BlueSpud said:

I was correct, tanks use a double/triple differential to vary the torque on each tread

Looks like you mean a differential stearing scheme that is not same that a differential gearbox. Really it one of 3 possible schemes of tank stearing (not including cluth breaking that has been used on first tanks) - first of it is a differential stearing that performed by slowing down internal trak-chain and accelerating a external track-chain. It scheme can not serve well for main intention of tank transmission - stabilize a engine loadout, becouse lead to significan increasing of loadout on turns, so applicable to light tanks with weak engines that have a hight working modes ratio only. Latest Soviet tank where its scheme has been used is IS-4 that has been sent to mass production at april of 1945. Other two schemes uses a slowdown of internal track-chain or both track-chains on turns. Its performed using friction clutch that limit a max torque that can be delivered tru the it or/and hydraulic transmission.  For example T-72 uses a  3 driving friction clutches - one (main clutch) that control a torque deliverd from engine to gearbox, and  2 side clutches that control a max torque delivered from gearbox to driving wheels, and  6 control clutches that control a torques betwin stages of planetary gearbox.

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

This topic is closed to new replies.

Advertisement