The setup consisted of two colliders, one for collision one for triggers. I’m not sure if you can merge these two but when I tried it you couldn’t so I just duplicated the same shape twice.
This also fixed the problem of the player losing all drag/friction when moving into a wall (aka you’re already on the wall but you move against it)
The mechanics around Wall Dragging were tricky to get around as I had three options:
1. Work with the linear drag rigidbody element to simulate a ‘slow-fall’ that happened only when attached to walls
2. Work with PhysicsMaterials with friction on colliders
3. Manually alter player velocity.y to simulate the drag instead
After looking at various options 2. didn’t work out and 1. was easier to implement so I decided to go with the first option
Above is the code for the Wall Dragging which is essentially builds upon the player.drag seen in the playerParachute post.
I also added a new boolean to check if the player is actually touching the wall, this is the second state introduced (the other being grounded) and will be used in Wall Jumping.
New Test Environment
I also added onto the existing Test Environment so that I could test Wall Jumping later
Compatability with Parachute Controls
Since the player is not grounded when Wall Dragging if the player wanted to Jump from the wall it would activate the playerParachute instead – to avert this and keep the one-button control mechanism ethos I added the wallTouch condition to the playerParachute code
Initial Wall Jump Style
In this initial version I simply exerted a force up. A problem that came from this was that you needed a stronger jumpForce to counteract the linear drag (as its drag in this system, not friction, after all) – however this causes a discrepancy: if you ever leave the wall which enacts linear drag you jump really high up but if you dont you barely jump at all.
I tried counteracting this by making the linear drag 0 when the button is pressed but this highlighted another problem: since the force is only exerted up you simply just go up, not across (preventing Wall Jumping), meaning that the player will always be in contact with the wall (and thus have linear drag of 20f)
Pushback Wall Jump Style
To counteract this I realised I needed to exert not only an upwards force but also a force that pushes the player sideways as well.
To determine which direction the sideways force would push, I needed to find a way to determine which side of the player was touching the wall.
At first I made a simple script that would flip the player’s sprites in the x direction depending on which way they were moving (and thus flip a collider object which would register walls) – but this conflicted with the 2D Dynamic Lights and Shadows plugin I downloaded so I had to do it another way.
First I developed a system to check if the player is touching any walls which I did by creating a new trigger collider object called wallCheckL (left).
I initially made two with for Left and Right but realised that if I integrate it within the existing (wallTouch) variable that I can just use an else statement instead of two ifs.
The code here works exactly like the code to set the (grounded) player state
With the new (wallTouchLeft) variable in place I modified the existing jump code, adding a horizontal force depending on which side the player is touching.