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: Code (CSharp): 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.
I don't think you need any scripting... try just making a super-slippery PhysicMaterial2D and put it on the inviso brick's collider. Zoop, down you go.
You don't say how you're moving the Rigidbody2D which is the most important part. Adding forces? Setting velocity directly? Note that you're changing the Rigidbody2D in the Update (per-frame) callback. Physics doesn't run per-frame unless you've asked it to so you might get many Update callbacks before the simulation runs. Lots of tutorials discuss this though. Note that you don't use another component to get a component on the GameObject: Code (CSharp): rigidBody2d = transform.GetComponent<Rigidbody2D>(); You can simply do this because your script is a component, just like the Transform: Code (CSharp): rigidBody2d = GetComponent<Rigidbody2D>(); To prove this, even this crazy code works: Code (CSharp): rigidBody2d = GetComponent<Rigidbody2D>().GetComponent<Rigidbody2D>().GetComponent<Rigidbody2D>();