Jump to content

PhysicalTrigger don't call callbacks when using collider node


photo

Recommended Posts

in the documentation it is mentioned that: 

 

Physical triggers fire callbacks when one of following gets inside or outside of them:

  • Physical objects.
  • Non-physical collider objects.

 

see also https://developer.unigine.com/en/docs/2.3/api/library/physics/class.physicaltrigger

 

However, for non-physical collider objects I couldn't get this to work. The physical trigger did register contacts, but no callbacks were called. Did a little digging, and from the following code excerpt:

void PhysicalTrigger::updateContacts() {
	
	// swap bodies
	bodies.swap(old_bodies);
	bodies.clear();
	
	// get collision
	shape->getCollision(contacts,engine.physics->getIFps());
	
	// update contacts
	for(int i = 0; i < contacts.size(); i++) {
		const Shape::Contact &c = contacts[i];
		
		// shape contact
		if(c.shapes[1] != NULL) {
			
			Body *body = c.shapes[1]->getBody();
			if((body->getPhysicalMask() & physical_mask) == 0) continue;
			
			Vector<Body*>::Iterator it = bodies.find(body);
			if(it == bodies.end()) {
				
				Vector<Body*>::Iterator it = old_bodies.find(body);
				if(it == old_bodies.end()) run_enter_callback(body);
				else old_bodies.remove(it);
				
				bodies.append(body);
			}
		}
	}
	
	// run leave callbacks
	for(int i = 0; i < old_bodies.size(); i++) {
		run_leave_callback(old_bodies[i]);
	}
}

It seems clear that indeed callbacks are only ever called if there is a collision involving a body. Note that c.shapes[1] is the shape of the other (not the trigger shape) and for a collider node this is always NULL (as it does not have a shape).

 

The callback argument (BodyPtr body) also hints quite strongly to the same conclusion, but theoretically for a non body collision the parameter passed could have been NULL.

 

This concerns version 2.3, but the documentation for 2.5 indicates no change.

 

Link to comment
  • 3 weeks later...

Hi Esger,

Indeed, currently callbacks are fired for physical objects only (i.e. with a body and a shape assigned). The documentation is updated. Maybe we'll add firing callbacks for non-physical objects later.

Thanks for the information!

Link to comment
×
×
  • Create New...