Contact callback script

The contact callback script, which is a simulation script and disabled by default, can be enabled via the environment dialog. When enabled, and the physics engine detected a collision between two respondable shapes, then the contact callback script will be called with appropriate arguments, allowing the user to customize the handling of contacts. The contact callback script might be called very often, sometimes more than several hundreds of times per simulation step (remember also that by default, the physics engine will be called 10 times for one simulation step). For that reason, keep things simple, in order to avoid slowing down the simulation.

Remember that custom contact handling is linked to a given scene, and objects/models will be behaving differently in a different scene. Contact callback scripts are only recomended for users that know exactly what they are doing. Following represents a default contact callback script:

-- Following data is handed over from V-REP:
objectHandle1,objectHandle2,engine=...

if not retTable1 then
    if engine==sim_physics_bullet then
        -- refer to simRegisterContactCallback for parameter description:
        retTable1={0,0,0}
        retTable2={1,0,0,0,0,0,0,0,0,0,0,0,0,0}
    end
    if engine==sim_physics_ode then
        -- refer to simRegisterContactCallback for parameter description:
        retTable1={0,4,4+8+16+2048}
        retTable2={0.25,0,0,0,0.25,0,0,0,0,0,0,0,0,0}
    end
    if engine==sim_physics_newton then
        -- Only called when the Newton plugin is compiled with the 'USE_THREAD_EMULATION'
        -- (or 'DG_USE_THREAD_EMULATION') define
        -- refer to simRegisterContactCallback for parameter description:
        retTable1={0,0,0}
        retTable2={1,1,0,0,0,0,0,0,0,0,0,0,0,0}
    end
    if engine==sim_physics_vortex then
        -- refer to simRegisterContactCallback for parameter description:
        retTable1={0,0,0}
        retTable2={0,0,0,0,0,0,0,0,0,0,0,0,0,0}
    end
end

-- Following data must be returned to V-REP:
-- -1 if you don't want to handle that contact here (i.e. the default handling will be used,
--    or the C/C++ callback will decide)
--  0 if the 2 items should not react to collision (this overrides the default contact handling)
--  1,tableValues1,tableValues2 if you handle this contact (this overrides the default contact handling)

return 1,retTable1,retTable2

Refer also to the API function simRegisterContactCallback, that allows you to handle dynamic contacts via C/C++ from within a plugin, which is a faster alternative than the contact callback script.


Recommended topics

  • Plugins