Collision speed issues

Topics: Developer Forum, Project Management Forum, User Forum
Aug 20, 2011 at 11:44 AM

I have three rectangular blocks: ground block, blue block, hero block. Ground is placed at the bottom of screen, blue block lay on ground block and hero block is falling down to blue block. I have listener which detects when hero is touched ground. There are two situations: 1) When hero falls down from low height to blue block its ok listener notify that hero contacts only blue block. 2) When hero falls down from a bit higher height to blue block listener notify that hero touches ground !!! How to solve this issue ?

    public HeroState GetHeroState()
    {
        ContactEdge contactEdge = null;

        if (heroBody != null) contactEdge = heroBody.ContactList;

        while (contactEdge != null)
        {
            if (heroBody.LinearVelocity == Vector2.Zero)
            {
                Texture2D textureA = (Texture2D)contactEdge.Contact.FixtureA.UserData;
                string textureAName = ((string)textureA.Tag).ToLower();
                Texture2D textureB = (Texture2D)contactEdge.Contact.FixtureB.UserData;
                string textureBName = ((string)textureB.Tag).ToLower();

                if (textureAName == "ground" || textureBName == "ground")
                    return HeroState.OnGroud;
                 else if (textureAName.Contains("blue") ||    textureBName.Contains("blue"))
                    return HeroState.OnHome;
            }

            contactEdge = contactEdge.Next;
        }

        return HeroState.Playing;
    }
Aug 21, 2011 at 10:55 AM

it is called tunneling and can be fixed if you set CCD of the hero to true (maybe you also need to set it for the others also, i dont really know)

hero.Body.IsBullet=true;

and i think it would be better is you set the user data to a custom struct and not to a texture because it seems you just need the Tag of it