PreSolve OnCollision

Oct 13, 2010 at 11:22 PM

I have implemented a onesidedplatform like in the testbed using the PreSolve method. It works great, but I use a groundSensor to see if the character is grounded. When the character is flying through the platform the sensor indicates that it is grounded And I don't want that. I check if the character is grounded using the OnCollision method. But I can't see any disable contacts in the OnCollision method,I tried "if (!contact.Enabled)" but no contacts are. Is it because my groundSensor is a sensor? or the OnCollision is triggered before PreSolve? or something else?

This shouldn't be that hard to solve

Oct 14, 2010 at 10:11 AM

When the OnCollision returns false, you are disabling the contact. I guess the OnCollision is called before the PreSolve (which should make sense, as the presolve seems to be about to calculate the collision reaction). In my game, I implemented one way platforms using the OnCollision method instead of the presolve.

Oct 14, 2010 at 9:00 PM

Thanks Pnikosis,

This is how I solved it. If there is a better way, let me here about it. I have to add my platform to the world before I add the character, so that the platforms OnCollision delegate triggers before the character.

Platforms OnCollision delegate

private bool OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
        {

            if (oneSided)
            {

                float offset = 0.23f;
                Character characterA = fixtureA.UserData as Character;
                Character characterB = fixtureB.UserData as Character;


                if (characterA != null)
                {
                    if (characterA.Wheel.Position.Y + offset > (position.Y - (size.Y / 2)) || characterA.jumpDownTimer > 0)
                    {
                        contact.Enabled = false;
                        return false;
                    }
                }
                if (characterB != null)
                {
                    if (characterB.Wheel.Position.Y + offset > (position.Y - (size.Y / 2)) || characterB.jumpDownTimer > 0)
                    {
                        contact.Enabled = false;
                        return false;
                    }
                }
            }

                    
            
            
            return true;
        }
GroundSensors OnCollision delegate
private bool OnCollisionGroundSensor(Fixture fixtureA, Fixture fixtureB, Contact contact)
        {
            if (contact.Enabled)
            {
                TicksGroundProxyCollision = Ticks;

                if (!contact.Enabled)
                {
                    jumpTick = 0;
                }
                if (charState != CharState.Stabelized)
                {
                    charState = CharState.Stabelized;
                    jumpTick = 0;
                }

                return true;
            }
            return false;
        }

 

Oct 15, 2010 at 7:42 AM

Is quite similar to the method I'm using (even I'm also using an offset). By the way, I think that the character will be always the fixtureB (fixtureA is the fixture you are delegating the OnCollision to), so you shouldn't need to check both fixtures. But I'm not 100% sure about this one.