Sticking to walls

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
XwingVmanX
Posts: 4
Joined: Wed Nov 14, 2012 11:44 pm

Sticking to walls

Post 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.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Sticking to walls

Post 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.
XwingVmanX
Posts: 4
Joined: Wed Nov 14, 2012 11:44 pm

Re: Sticking to walls

Post by XwingVmanX »

How do I eliminate the friction with the wall?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Sticking to walls

Post 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());
            }
        }
XwingVmanX
Posts: 4
Joined: Wed Nov 14, 2012 11:44 pm

Re: Sticking to walls

Post 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.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Sticking to walls

Post 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).
XwingVmanX
Posts: 4
Joined: Wed Nov 14, 2012 11:44 pm

Re: Sticking to walls

Post by XwingVmanX »

Awesome, that is what I needed to know. I didn't realize material was located within entity. Thanks for the help.
Post Reply