Page 1 of 1

Collision Only With the Floor: Revisited

Posted: 21 Nov 2019, 18:44
by Sniggyfigbat
Very similarly to this thread, I am attempting to run multiple robots in the same space, without mutual collision. Essentially, I'm trying to simulate generations of evolutionarily-tweaked robots running a course, 100 robots (1 generation) at a time.

Unfortunately, that thread is now outdated, and it is recommended to use a contact callback function instead. That's fine, but I can't get it to work. I set ignoreContact to true and collisionResponse to false, but, while the function is definitely being called, the robot stubbornly refuses to phase through the wall.

Code: Select all

function sysCall_contactCallback(inData)
    sim.addStatusbarMessage("Collision callback triggered.")

    local retData={}
    retData.ignoreContact=true -- handle contact here
    retData.collisionResponse=false
    return retData
end
I'm fairly certain I'm putting it on the right sub-object (it's the one with the 'Collidable' property), so I'm a bit confused as to what I'm doing wrong. In addition, I'd rather not have to put a script on every collidable part of the robot, if that's something I can avoid.

What's the best solution to this in the current version of V-REP?

Re: Collision Only With the Floor: Revisited

Posted: 21 Nov 2019, 19:06
by Sniggyfigbat
After some fiddling, I have arrived at a terrible and inefficient solution:

Code: Select all

function sysCall_init()
    collection = sim.getCollectionHandle("EverythingButRobot")
    collidables = {}
end

function sysCall_contactCallback(inData)
    sim.addStatusbarMessage("Collision callback running.")

    local retData={}
    retData.ignoreContact=false -- handle contact here
    retData.collisionResponse=false

    collidables = sim.getCollectionObjects(collection)
    for key, handle in pairs(collidables) do
        if handle == inData.handle1 or handle == inData.handle2 then
        retData.ignoreContact=true
        end
    end

    return retData
end
This works, but barely runs. There must be a better solution. Please help.

Re: Collision Only With the Floor: Revisited

Posted: 27 Nov 2019, 14:23
by coppelia
There is probably a better solution:

Create a robot model like:

Code: Select all

floor --> robot
when you spawn a new robot, simply spawn the floor and the robot. Make sure that the floor is static and the robot is attached to that floor. Also make sure that in the robot, all respondable shapes have their global respondable masks cleared.

This way, the robot will only respond to collision with objects in its hierarchy, and robot-robot collisions won't be noticed.

Cheers