I am working on a project that requires the player to be able to not only stick to a wall but also be able to jump off the wall and stick to another wall. Every time I try to mess wit the RigidBody2D variables it does not seem to make any difference, the character simple slides off. I already have the character movement working properly but figuring out how to make the character be able to stick to the walls is difficult. I also have a friction material on the wall already. Is it possible to allow the character to not be a rigid body? Any help is appreciated! Thanks in advance!
Yes you can try two things make the rigidbody kinematic (best bet in my option) or turn off the gravisty by doing myRigidbody2D.gravityScale = 0;
.
Kinematic means in simple terms that the rigidbody will ignore external forces, but still can move and interact with other rigidbodies;
A while ago I made a game very similar to this. It was basically a square that would jump around a scene and stick to walls. The way I approached it was to freeze the X and Y positions as well as the Z rotation whenever OnCollisionEnter() was triggered.
Here is the code I used for my game.
void OnCollisionEnter2D(Collision2D collison){
if(collison.transform.tag != "Player"){
if (!Input.GetMouseButtonDown (0)) {
body.constraints = RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation;
//print ("Col");
canJump = true;
//print ("Enter");
}
}
}
void OnCollisionExit2D(Collision2D collision){
if(collision.transform.tag != "Player"){
body.constraints = RigidbodyConstraints2D.None;
canJump = false;
//print ("Exit");
}
}
void OnCollisionStay2D(Collision2D collision){
if(collision.transform.tag != "Player"){
//body.constraints = RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation;
canJump = true;
//rigidbody2D.v = new Vector2 (0, 0);
//print ("Stay");
}
}
Hope this helps.