Terrain Collision

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Terrain Collision

Postby MeltingPlastic » Mon Oct 01, 2018 7:54 pm

I recently made a demo of a vehicle using just the dCustomJoint library:
https://www.youtube.com/watch?time_continue=80&v=g_h0nqcc5Jw

The wheels seem to jump up quite alot every so often like they are hitting something invisible on the terrain mesh. but otherwise that jump up and down only slightly. Could this be improved if I oversampled (interpolated)my hieghtfield data and passed in a smoother terrain? Or maybe another approach is to tweek the tire material softness? could there be a bug in the terrain collision code? (I only ask because the wheel only intermittently jump - seemingling not on every patch transition).

I know I'm not using the vehicle managers, Right now I want to see what I can do with the general api.

Thanks!
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: Terrain Collision

Postby Dave Gravel » Mon Oct 01, 2018 9:06 pm

It make very longtime that I use multibody vehicle.
I think it is hard to avoid all edges from the terrain with the multibody solution.
I think it can cost a lot in physic process to fix this problem totally.
You can maybe avoid some edge problem by doing the acceleration gradually on the tire.
And try to don't overpass the physic rotation limite by step.
It don't fix the problem when the vehicle go at high speed over terrain.

I have always get this problem with multibody and terrain.
I have already get better result from older newton version but the problem stay present anyway.
It is not a problem in coming only from newton, I have seen the exact same problem from other physics engine.

Exemple I have already remake my multibody construction under unreal engine without newton and I getting exactly the same problem.
https://www.youtube.com/watch?v=V6Dbk3mjFuE
Take a look at 2:24mins and watch the vehicle tire.

The multibody tire work good over a simple collision but when you have many edges it start to get problems.
You can maybe hide the problem with different suspenssion setting and mass setting but it never go totally.

The best for vehicle with terrain is surely to use raycast vehicle, or the new vehicle implementation in newton sdk.

Edited:
You can try to comment out the tire projection if you use it.
I talk about this line cTireSpring->TireMatrixProjection();
I don't have test with last sdk and terrain maybe the tire projection aggravating the problem.
It is a very important part of code for the multibody vehicle but try without just for see if you get same edge problem.
If the problem are less present without the tire projection, Maybe this part of code need some fix or a better implementation.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 800
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Terrain Collision

Postby MeltingPlastic » Mon Oct 01, 2018 10:42 pm

Thanks Dave! In the video I am not using your tire joint. Just:

carBody <--dCustomSlider--> hub <--dCustomHinge--> wheel

I might try your tire joint next. It does get rid of the hub body which would be nice. although I can see how it would fix the terrain jump problem. Its almost as if there are slight discontinuities in the collision mesh vertices sometimes.

As an experiment I wanted to throw out any contacts that are generated with a impulse greater than a threshold, but the only function I can find to get the value of the normal impulse of a contact is "NewtonMaterialGetContactMaxNormalImpact" I'm not sure that's what I want because It says it is the "Max" impact. Basically I want to throw out contacts that have a high impact value so that the wheel jumps would be ignored. Better yet - instead of throwing out the contact, modifying the impact value to a lower value.
Julio, are these kind of functions possible - or do they even make sense to use?[/
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: Terrain Collision

Postby Julio Jerez » Tue Oct 02, 2018 2:14 pm

As an experiment I wanted to throw out any contacts that are generated with a impulse greater than a threshold, but the only function I can find to get the value of the normal impulse of a contact is "NewtonMaterialGetContactMaxNormalImpact" I'm not sure that's what I want because It says it is the "Max" impact. Basically I want to throw out contacts that have a high impact value so that the wheel jumps would be ignored. Better yet - instead of throwing out the contact, modifying the impact value to a lower value.
Julio, are these kind of functions possible - or do they even make sense to use?


that's not really possible with engines like newton, because contact are generated first then they are put together and the solver calculate the impulse.

anyway a couple of things on this problem.
This is a problem I have been struggling for many years and it is one more reason yet for not making rigid body cars using a rigid body solver.
the explanation is long for why this happen, but I can summarize like this.

-the wheel is a mall body that is sandwiched between two large bodies (the chassis and the ground)
-since the wheel is attached to the body with a spring joint along the vertical axis, this means that as the car and the wheel move horizontally they do not follow the same trajectory, the horizontal speed is the same but the vertical speed is different.

What happens is that for the chassis the motion appears to be small enough that any collision penetration in small relative to the body size.
To the wheel, she is moving with at least one contact touching the floor, for the most part, however each time the wheel loses that ground contact, now the solver see a body of small mass subjected to a very large force (the suspension) therefore in one step it acquire a very large velocity that make penetrate the ground by a significant value.
the higher the horizontal velocity the more likely the wheel trajectory diverge for the ground surface and it is inevitable that it will be air borne is some occasions.
basically it is a continue collision problem but along one direction of motion.

I have implemented many hacked solution over the years to combat this problem, one is the chamfered cylinder which is like a donought that generate only one contact, so the contact is almost always align to the wheel center. this solve the edge problem but not the airborne problem.

the only thing that can solve the airborne problem are all expensive and complicated.
1-continue collision (a bad idea for articulated bodies that move at high and low speed at the same time)
2-higher simulation rate (also a bad idea because the is a global setting)
3-a use define contact generation for generation for directional continue collision (this is the trick I am use now for the vehicle with mixed result)

for option 3 you can see how this is set up in the function
Code: Select all
dCustomVehicleControllerManager::dCustomVehicleControllerManager(NewtonWorld* const world, int materialCount, int* const materialsList)
   :dCustomControllerManager<dCustomVehicleController> (world, VEHICLE_PLUGIN_NAME)
   ,m_tireMaterial(NewtonMaterialCreateGroupID(world))
{
   // create the normalized size tire shape
   m_tireShapeTemplate = NewtonCreateChamferCylinder(world, 0.5f, 1.0f, 0, NULL);
   m_tireShapeTemplateData = NewtonCollisionDataPointer(m_tireShapeTemplate);

   // create a tire material and associate with the material the vehicle new to collide
   for (int i = 0; i < materialCount; i ++) {
      NewtonMaterialSetCallbackUserData (world, m_tireMaterial, materialsList[i], this);
      if (m_tireMaterial != materialsList[i]) {
         NewtonMaterialSetContactGenerationCallback (world, m_tireMaterial, materialsList[i], OnContactGeneration);
      }
      NewtonMaterialSetCollisionCallback(world, m_tireMaterial, materialsList[i], OnTireAabbOverlap, OnTireContactsProcess);
   }
}


basically the vehicle implement this function,
void dCustomVehicleController::Collide(dWheelJoint* const tire, int threadIndex)

to calculate the tires collision at the beginning by using convex cast to determine if the tire will be airborne or not.
then it calculate the contacts and save them for each tire for later usage.
the contact callback simply look up the body and use the contacts generated by the vehicle.
it is like a ray cast but much better, because is a full collision.

this I found to be too complex, and when adding the other reasons why rigid body car are not a good idea, this is why I am making a new vehicle that is not raycast but that will do all these things by implementing an immediate mode physics solver that allow to do this things without tricking the generic solver.

here is something you can do to test is what I say is true or not, I am assuming you are running at 60 fps.
jack up the number of sub steps, say 4 or maybe 8, then you will see that the problem happen at higher vehicle speed, of course you can see why this is not a general solution.

My recommendation is that You and Dave be early adopters of the newer vehicle, It will be designed to cope with this issues, to be fast, accurate and fun to drive.
Because it will use the equations that govern vehicle dynamics which are some what more elaborated than simple right body physics.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Terrain Collision

Postby MeltingPlastic » Tue Oct 02, 2018 3:19 pm

Thanks for the explanation Julio! Sorry if I bring up pain points :|.

I'll have to think of a good way to use the new vehicle manager in the Urho API. right now I have a general architecture of

node--->RigidBody
|-->CollisionShape

But I think I can make a custom component that just builds a vehicle with the new managers.

I feel like I am nearing the end of getting the general things like bodies, shapes, joints and materials in place and can focus on the other things.
MeltingPlastic
 
Posts: 237
Joined: Fri Feb 07, 2014 11:30 pm

Re: Terrain Collision

Postby Julio Jerez » Tue Oct 02, 2018 4:17 pm

It be easy. here are few pointers.
I assume you made dummy entity that is just the to hold the world component. also that a node can hold more than one component.

if this is the case, you jut have that component making a vehicle manage member,
or you can make a vehicle component manager and attach to the work entity. the take car of the vehicle manager.

to make a vehicle you make a rigid body just like you have been doing until now.
you make a series of components that can be assigned to a rigid bodid

the first one is the vehicle chassis which has a reference to the Vehicle manager, this will allow you to turn any vehicle into a vehicle chassis.

the next Is the wheel, which will have a reference to the chassis. therefore making the chassis a required component.

The wheel is a component that is attached to some game node that make a tire,
this can be a child of even a work entity is does not matter.
with the his you now have a vehicle that does not brake any rule of your component system.

later there will be other components that will attached to a vehicle to give functionality.
engine, with transition and differential, input control.
for example the can be multiple drive train front, rear and four wheel drive.
an there you have it a basic vehicle.

any variation for the procedure should work for your engine.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 4 guests

cron