Jump to content

[SOLVED] How can I control collision?? (node)


photo

Recommended Posts

Hi,

I want to access the node and control the collision with the code.

How can i access collision in node??

I want to implement the function of Grabbing nodes.

 

Regards,

shchoe

Link to comment

I want grab node, use hand tracking

I'm curious about surface collision of the object

ex) mesh collider

I'm looking for a way to access the surface collision with the code.

Thank you

 

Link to comment

Hello.

You can get information about contacts using the ShapeContact class. For example, let's create interactive objects using ObjectMeshStatic. Add a rigid body and one shape to each of them. Objects will be grab at close range, so sphere intersecton will be used to check. We will only get contacts for nearby objects and then check if the mesh is in collision.

void getObjContacts(const ObjectPtr &obj, float radius, Vector<ShapeContactPtr> &all_contacts)
{
	all_contacts.clear();

	WorldBoundSphere bs(obj->getWorldPosition(), radius);
	Vector<NodePtr> nodes;
	World::getIntersection(bs, Node::OBJECT_MESH_STATIC, nodes);

	for (int i = 0; i < nodes.size(); i++)
	{
		BodyPtr body = nodes[i]->getObjectBody();
		if (!body || body->getNumShapes() == 0)
			continue;

		ShapePtr shape = body->getShape(0);
		Vector<ShapeContactPtr> contacts;
		shape->getCollision(contacts);
		for (int j = 0; j < contacts.size(); j++)
		{
			if (contacts[j]->getObject() == obj)
				all_contacts.append(contacts[j]);
		}
	}
}

The result of this function looks like this:

contacts.PNG

  • Like 1
Link to comment
  • silent changed the title to [SOLVED] How can I control collision?? (node)
×
×
  • Create New...