Jump to content

[SOLVED] Remove collision in "Creating a Car with Wheel Joints" example


photo

Recommended Posts

I want to create many cars from the example(Creating a Car with Wheel Joints) without colliding. If I understand correctly for this I should use Eclusion mask. And I can do it, but only for the car body.
But it doesn't work for car wheels. Perhaps because the wheels have no shape and ray casting is used to detect collision of the wheel with a surface. But knowing this, I still cannot remove collisions.

 

Edited by NotNa19
Link to comment

Hello @NotNa19!

Indeed, Wheel Joints use ray casting (Physics Intersections) for collision detection instead of shape-based physical collisions, and they have intrinsic values for wheel radius and mass for simulation. So the collisions you observe are not between wheel joints but between joints and polygon surfaces of car wheels and body.

In the given exmaple, each joint detects Physics Intersections with ground, wheels and physical bodies.

If you want to simply disable all collisions between cars, the solution is to disable Physics Intersections for wheels and physical bodies (or set their Physics Intersection masks to 0):

Spoiler
ObjectMeshDynamicPtr createBody(char* name, const vec3& size, float mass, const vec4& color, const Mat4& transform)
{
	/* .. */
	BodyRigidPtr body = BodyRigid::create(OMD);

	ShapeBoxPtr shape = ShapeBox::create(size);
  	// set the Exclusion mask for car bodies so they ignore each other
	shape->setExclusionMask(1);
  	// the car body has a shape attached that takes part in collision detection
  	// so we disable physics intersection mask for it
	shape->setPhysicsIntersectionMask(0);
	shape->setMass(mass);
	body->addShape(shape, translate(vec3(0.0f)));

	return OMD;
}

ObjectMeshDynamicPtr createWheel(NodePtr frame, char* name, float radius, float height, const Mat4& transform)
{
	ObjectMeshDynamicPtr OMD = Primitives::createCylinder(radius, height, 1, 32);
  	/* .. */

  	// here we disable Physics Intersection for wheel surfaces because
  	// wheels have no shapes attached, so collision is detected with the polygon surface
	OMD->setPhysicsIntersection(0, 0);

	// adding a rigid body 
	BodyRigidPtr body = BodyRigid::create(OMD);

	return OMD;
}

 

After these changes, wheel joints will detect collisions only with surfaces and shapes with Physics Intersection enabled (and matching mask), such as the ground plane, and car bodies will ignore each other as well.

cars_demo.gif

Here's a complete updated source code just in case it's needed.

cars_without_collisions.zip

  • Like 1
  • Thanks 1
Link to comment
  • NotNa19 changed the title to [SOLVED] Remove collision in "Creating a Car with Wheel Joints" example
×
×
  • Create New...