Replies: 1 comment
-
Webots does automatically detect collisions and apply the contact forces whenever necessary. The collision detection mechanism is based on the shapes specified in the
#define ROBOT_RADIUS ...
...
int are_colliding(WbFieldRef trans1, WbFieldRef trans2) {
const double *p1 = wb_supervisor_field_get_sf_vec3f(trans1);
const double *p2 = wb_supervisor_field_get_sf_vec3f(trans2);
double dx = p2[0] - p1[0];
double dz = p2[2] - p1[2];
double dz = p2[2] - p1[2];
return sqrt(dx * dx + dz * dz) < 2.0 * ROBOT_RADIUS;
}
...
// do this once only, in the initialization
WbNodeRef robot1 = wb_supervisor_node_get_from_def("MY_ROBOT1");
WbNodeRef robot2 = wb_supervisor_node_get_from_def("MY_ROBOT2");
WbFieldRef trans1 = wb_supervisor_node_get_field(robot1, "translation");
WbFieldRef trans2 = wb_supervisor_node_get_field(robot2, "translation");
...
// detect collision
if (are_colliding(trans1, trans2)) {
...
}
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I need to programmatically detect collisions between objects while the simulation is running.
How can I achieve this?
Beta Was this translation helpful? Give feedback.
All reactions