I am working on a 2D game, but my character wants to cling to walls when I jump to them and as long as I try to walk against it I will stay there. The solution that I could find on answers/forums involved adding a collision box with 0 friction. I wasn’t sure if adding a lot of collision boxes just to keep players from sticking to the sides would be bad for performance. Would it be better (more efficient) to make a script to detect if the player is clinging to walls with ray casts and adjust the friction of the player character itself? If so, I was hoping to make some walls semi cling-able. :]
Not sure I understand why you can’t just modify the wall that’s already there?
Anyway, adding static colliders has relatively little impact on performance. Presumably they’re well indexed by layer and location so only the most relevant are checked.
I was hoping to get around having to use GetComponent to get the PhysicsMaterial2D component of the targeted wall.
You haven’t actually explained why you cannot just set the material in the Inspector.
Oh, my bad. I thought you were wondering why I don’t edit the wall through script instead of the player.
To avoid having a collider to walk on and two extra colliders on the sides to stop the wall grip. If doing that for each walkable platform with exposed sides won’t be a problem, then I guess I can. 3 box colliders for a platform seemed overkill considering there will probably be a lot of exposed sides.
Oh, I see; you want a rectangle with different material properties on the sides. I had a very similar problem and just used multiple colliders with different materials. As I said before, extra colliders don’t seem to add much overhead, particularly if they’re not attached to dynamic rigidbodies.
Use EdgeCollider2D instead of BoxColliders, for most surfaces. They work better when you tile them as well, since if you’re using a BoxCollider on the player as well, you’ll end up with an issue where the player gets stuck at the transition between BoxColliders sometimes. This won’t happen with EdgeColliders.