Can the vehicle physics ignore a Collider with specific Tag?

I have to different Kinds of Colliders (“Environment” and “Mud”). The vehicle Physics should collide with the “Environment” Tagged Collider but not with the “Mud”-Tagged one. Is that possible?

My guess would be to set that up when the Car get’s Created in the vehicle.js script.

// Create vehicle
var tuning = new Ammo.btVehicleTuning();
var vehicleRayCaster = new Ammo.btDefaultVehicleRaycaster(dynamicsWorld);
var vehicle = new Ammo.btRaycastVehicle(tuning, body, vehicleRayCaster);
vehicle.setCoordinateSystem(0, 1, 2);

Link to the Project:
OnlineRunner | Editor (playcanvas.com)

Thanks in advance,
Konstantin

Welcome to PlayCanvas!

I’m afraid this is not possible with the default raycast vehicle in Ammo. In general, not related to btDefaultVehicleRaycaster, to filter out the raycast results, you would set a mask/filter on a raycast callback function. Internally, the vehicle raycaster is using a default raycast callback, which is set to default values, which is colliding with everything.

This is not impossible, though, but troublesome. Here are a few options, but all might be non-trivial:

  1. Use C++ to derive the default vehicle raycaster class in Bullet physics sources that also accepts filter/masks bits. Then expose it in the IDL bindings file and build a new Ammo version using the new definition. In Javascript you can then pass the filter/mask on vehicle instantiation.

  2. Do not use btDefaultVehicleRaycaster, but create a rigidbody with 4 downward rays. Same setup as in btDefaultVehicleRaycaster, basically. Since you control the raycasts here, you can also set filters and masks bits. You would then have to manually control the forces applied to the rigidbody, depending on raycast results to balance the vehicle above ground.

  3. Do not use raycasts, but a multibody connected with joints. You can have 2 back wheels as a single compound rigibody connected to the main body with a hinge joint, as they do not rotate left and right. Then use 2 hinge joints for the front wheels. One to rotate in place, another to rotate on local Y axis. You can also use only 1 hinge per front and back wheels and move the body by force, without relying on wheels friction. You would also have to apply additional forces on the main body to keep the vehicle in balance.

2 Likes