I am working on a 2D platformer and wanted to put a couple of invisible walls on a scene. All I did was add an empty game object and a box collider 2D. It stops the player, HOWEVER the player will “stick” to the wall as long as the horizontal button is pressed. I would like the character to fall at the speed of gravity. I do not know if this is setting that I would need to set up on a component or not.
I tried to set up something in my script to fix this but that did not work. What I had was:
public Transform groundCheckPoint;
public Transform wallGrabPoint;
private bool canGrab, isGrabbing;
private float gravityStore;
// Layer Masks
public LayerMask whatIsGround;
public LayerMask whatIsWall;
...
private void Start()
{
rigidBody2d = transform.GetComponent<Rigidbody2D>();
gravityStore = rigidBody2d.gravityScale;
}
void Update
{
...
canGrab = Physics2D.OverlapCircle(wallGrabPoint.position, .2f, whatIsWall);
...
if (!canGrab)
{
rigidBody2d.gravityScale = gravityStore;
}
}
The layers for the invisible walls were not set to ‘whatIsWall’ on the player character. The thought was if the user cannot grab, then the gravity that is applied would be that of the gravity scale at the start.

