@@ -877,18 +877,50 @@ is a shape that detects overlap but does not produce a response.
877877
878878You can flag any shape as being a sensor. Sensors may be static,
879879kinematic, or dynamic. Remember that you may have multiple shapes per
880- body and you can have any mix of sensors and solid shapes. Also,
881- sensors only form contacts when at least one body is dynamic, so you
882- will not get sensors overlap detection for kinematic versus kinematic,
883- kinematic versus static, or static versus static. Finally sensors do not
880+ body and you can have any mix of sensors and solid shapes. Sensors do not
884881detect other sensors.
885882
883+ Sensors are processed at the end of the world step and generate begin and end
884+ events without delay. User operations may cause overlaps to begin or end. These
885+ are processed the next time step. Such operations include:
886+ - destroying a body or shape
887+ - changing a shape filter
888+ - disabling or enabling a body
889+ - setting a body transform
890+
886891Sensors do not detect objects that pass through the sensor shape within
887892one time step. If you have fast moving object and/or small sensors then you
888893should use a ray or shape cast to detect these events.
889894
890- Sensor overlap detection is achieved using events, which are described
891- below.
895+ You can access the current sensor overlaps. Be careful because some shape ids may
896+ be invalid due to a shape being destroyed. Use ` b2Shape_IsValid ` to ensure an
897+ overlapping shape is still valid.
898+
899+ ``` cpp
900+ // First determine the required array capacity to hold all the overlapping shape ids.
901+ int capacity = b2Shape_GetSensorCapacity( sensorShapeId );
902+ std::vector<b2ShapeId> overlaps;
903+ overlaps.resize( capacity );
904+
905+ // Now get all overlaps and record the actual count
906+ int count = b2Shape_GetSensorOverlaps( sensorShapeId, overlaps.data(), capacity );
907+ overlaps.resize( count );
908+
909+ for ( int i = 0 ; i < count; ++i )
910+ {
911+ b2ShapeId visitorId = overlaps[i];
912+
913+ // Ensure the visitorId is valid
914+ if ( b2Shape_IsValid( visitorId ) == false )
915+ {
916+ continue;
917+ }
918+
919+ // process overlap using game logic
920+ }
921+ ```
922+
923+ Sensor overlap can also be achieved using events, which are described below.
892924
893925## Contacts
894926Contacts are internal objects created by Box2D to manage collision between pairs of
@@ -1028,18 +1060,6 @@ for (int i = 0; i < sensorEvents.endCount; ++i)
10281060Sensor events should be processed after the world step and before other game logic. This should
10291061help you avoid processing stale data.
10301062
1031- There are several user operations that can cause sensors to stop touching. Such operations
1032- include:
1033- - destroying a body or shape
1034- - changing the filter on a shape
1035- - disabling a body
1036- - setting the body transform
1037- These may generate end-touch events and these events are included with simulation events available
1038- after the next call to ` b2World_Step ` .
1039-
1040- Sensor events are only enabled for a non-sensor shape if ` b2ShapeDef::enableSensorEvents `
1041- is true.
1042-
10431063### Contact Events
10441064Contact events are available after each world step. Like sensor events these should be
10451065retrieved and processed before performing other game logic. Otherwise
0 commit comments