[Solved]Collide with physics turned off for some objects and on for others

Topics: User Forum
Apr 18, 2010 at 2:19 AM

So what I'm trying to do is have an item that collides with the ground and has a reaction, but when it collides with the player it doesn't.  More or less I want the item(object) to land on the ground and stay there. Then when the player collides with it, physics is ignored but the collision event still happens.  I thought that collision categories would work but once the item is set to ignore the collisions with the player it no longer fires the OnCollision event.  I even tried turning collisionResponseEnabled to false but then it just falls through the ground.   I tried a couple of other little cheats but so far nothing has really been effective enough.  Currently I'm looking into Arbiters. 

I could probably go a different route than the OnCollision event, but I really don't want to have to run my own collision detection on the side.  I'm really hoping there is a simple solution.  Thanks in advance.

Apr 18, 2010 at 8:27 AM

Nvm I found a cheap solution.  For my object I created two sets of bodies and geometries so one was the actual body the other I turned the CollisionResponseEnabled to false and constantly update its position with the original body's position.  Then I run a OnCollision event on the secondary body/geom. A little bit of a hack but simple and not to taxing.  If there is a better way of fixing this issue I'm still open to suggestions but for now I'm jsut going to use what I have and keep going.

 

Apr 18, 2010 at 5:52 PM

If you want the item to not collide with the player just return false in OnCollision when the item hits a player and it won't collide

Pseudo code.

//this is the players OnCollision
public bool OnCollision(Geom self, Geom other, ContactList contacts)
{
    if (other.CollisionCategories == items Col cat)
    {
        //do stuff
        return false;
    }
    

    return true;
}

Hope this helps.

Apr 19, 2010 at 1:09 AM

That did it thanks man, much appreciated.