I have a 2D scene in which all gravity is zero (in both Physics and Physics 2D settings) and a player with a Rigidbody 2D which has the Gravity Scale set to 0. I have a script which imposes arbitrary gravitational forces on the player (e.g. towards the ground, the ceiling, the walls). The force is uniform and gravity really is zero; when I turn off the gravity script the Rigidbody floats with no other forces imposed on it.
The problem is that when the player is moved along the surfaces of the room by adding force to the Rigidbody, there is clearly a difference between the speed at which it moves on the ground and the speed at which it moves on the ceiling and walls. The only reason I can think of to explain this is that there seems to be less friction on the ceiling than on the ground.
I’ve tried creating a Physics Material and using different settings for that and I’ve tried different Friction Types in Project Settings > Physics (there doesn’t seem to be a Friction Type setting specifically for 2D) but I get the same results no matter what.
Has anyone else encountered this before? Is there some other place in which friction is set for 2D Physics that takes Y position into account?
Create a Physics Material 2D, set its friction to zero and attach it to the player.
Thanks for your reply. As I mentioned, I’ve already created a Physics Material 2D (for both the player’s Rigidbody2D and the ground’s PolygonCollider2D) and tried different settings, including setting the friction to zero. Even when I do this, there is still a clearly noticeable difference in friction between when the player is on the ground vs when the player is on the ceiling. It’s as if there is ice on the top of the surface but normal ground on the bottom.
A couple other points of clarification:
- I’m rotating the player so it’s always contacting the ground at the same point (i.e. the bottom side of a CapsuleCollider2D)
- I’m using one continuous surface for the ground—a PhysicsCollider2D that is created around a spline—so it’s all the same ground material
I’ve attached an image to further illustrate. There’s a Debug ray being drawn below the player showing the force of gravity. This is always perpendicular to the underlying spline.
After some more debugging, I found the problem:
mRigidbody.AddRelativeForce(moveVector * moveForce - mRigidbody.velocity);
In attempting to limit the player’s speed, I was subtracting velocity in the world from the relative force applied (which of course worked fine when I was still working in a purely top down world). Anyway thanks to all who looked at this and hope this helps someone later.