Page 1 of 1

Sticking to walls

Posted: Thu Nov 15, 2012 12:01 am
by XwingVmanX
I am currently making a game with platforming elements and I am running into a problem where if a player jumps into the wall and continues moving into the wall they stay at that location on the wall.

For Example:
Image

So the player will stay like that while they push left, once they stop trying to move left they will drop like they should. I don't understand why gravity isn't effecting the play in this situation.

Re: Sticking to walls

Posted: Thu Nov 15, 2012 12:09 am
by Norbo
If your character is able to shove itself into the wall with significant force, friction will stop the character from falling (recall that the maximum force of friction = coefficient * normal force).

To stop this from happening, either lessen the air control strength or lower/eliminate friction between the character and the walls.

Re: Sticking to walls

Posted: Thu Nov 15, 2012 12:16 am
by XwingVmanX
How do I eliminate the friction with the wall?

Re: Sticking to walls

Posted: Thu Nov 15, 2012 12:27 am
by Norbo
That could depend on how you are handling the character, but here's a few general ways:

1) Create a Material and use it for the environment. Create another Material and use it for the character. Add a custom material interaction between them.

Code: Select all

                    MaterialManager.MaterialInteractions.Add(new MaterialPair(characterEntity.Material, environment.Material),
                        (Material a, Material b, out InteractionProperties properties) =>
                        {
                            properties.Bounciness = 0;
                            properties.StaticFriction = 0;
                            properties.KineticFriction = 0;
                        });
2) Modify the MaterialManager.MaterialBlender to conditionally return no friction based on custom logic. This delegate is used as a fallback for any material pair which does not have a specific handler specified in the MaterialInteractions dictionary.

3) Hook an event handler for the character to eliminate all friction with the character body, regardless of material interaction properties. The CharacterController does this by hooking the following event to the Body.CollisionInformation.Events.DetectingInitialCollision event:

Code: Select all

        void RemoveFriction(EntityCollidable sender, BroadPhaseEntry other, NarrowPhasePair pair)
        {
            var collidablePair = pair as CollidablePairHandler;
            if (collidablePair != null)
            {
                //The default values for InteractionProperties is all zeroes- zero friction, zero bounciness.
                //That's exactly how we want the character to behave when hitting objects.
                collidablePair.UpdateMaterialProperties(new InteractionProperties());
            }
        }

Re: Sticking to walls

Posted: Thu Nov 22, 2012 6:50 pm
by XwingVmanX
Can you expand upon the first method you mentioned. I don't understand how the material affects the physic boxes.

The way I have the code set up is the environment is made up of static boxes based off the EntityModel from BepuDemo (modified a little) and when created is passed its physics box. The player class is a child of the EntityModel. In EntityModel I created the material and once the player and the environment is created I used the method you showed me.

Re: Sticking to walls

Posted: Thu Nov 22, 2012 7:50 pm
by Norbo
The Entity and StaticMesh each have a Material property. Set the Material property to the desired material. When two objects collide, their materials are compared against each other using the MaterialManager to figure out the collision's interaction properties (kinetic and static friction and bounciness).

Re: Sticking to walls

Posted: Sun Nov 25, 2012 3:47 am
by XwingVmanX
Awesome, that is what I needed to know. I didn't realize material was located within entity. Thanks for the help.