How do you slow down a motorbike's speed when it's running off track i.e on the grass. I guess the speed should decrease. FYI:I'm using just a box collider. No wheels! Thanks
Step one: Detection / Sensor Component
You need to determine the surface being used by the active object. You can do this by any parameter. Colour, type, Tag or any other measurement tool you wish to look for. Make sure you don't look for data you don't need by making only active objects perform such a search, continously looking/scanning for paramaters PER OBJECT can quickly cascade in a massive search taxing the performance heavily
Step two: Response
The active object has "seen" that the surface area has changed. Change the parameters to adapt to the new envioronment. Edit the physical properties of the vehicle by using another set in a simple condition mechanism. You can make a simple if switch or type definition using enum to do such a thing.
if (type matches type a)
{
//Use physical property set A
}
else if(type matches type b)
{
//Use physical property set B
}
else //default case
{
//if detection failed use a default set and send information for debug mode that
//this situation is occuring
}
or a switch doing such
I can think of two techniques, build your track from geometry and attach appropriate physics materials to the ground submeshes. From there you can ray cast from each wheel to the bottom of the wheel (or bottom of car), and poll for the material your on. If nothing you are in the air. If the material is non pavement then speed--
Method 2: have a mask representing the course (think of a top down camera looking down on the track) where the 'non alpha' pixels represent pavement. Then do a world position -> U,V look up on this texture.