- Home /
friction different on ceiling in zero gravity 2D
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?
Answer by turowskipaul · Mar 03, 2019 at 01:42 AM
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.
Answer by MSavioti · Feb 26, 2019 at 04:14 AM
Create a Physics Material 2D, set its friction to zero and attach it to the player.
Answer by turowskipaul · Feb 26, 2019 at 01:29 PM
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.
Update: been testing this more and still stumped, but I thought I'd share what I've done in case it helps.
I made the ground shape symmetrical: same behavior.
I put the player outside the shape ins$$anonymous$$d of inside: no change. That is, the player has much less friction when on the bottom of the loop (i.e. upside down) than on the top. To elaborate, applying a short push while the player is on the side sends it sailing around the bottom of the curve to the other side, while it takes sustained force to move it around the top of the curve.
I thought it might have something to do with the direction of the spline (around which the Polygon Collider 2D is created) so I reversed the spline and rebuilt. Same behavior.
I also tried using different 2D collider shapes (box, circle). No luck.
I tried attaching screenshots of the Polygon Collider 2D as well as my 2D Physics settings in case I'm missing something there, but photo upload doesn't seem to be working right now. I can try uploading these later if it would be useful.
Your answer
Follow this Question
Related Questions
Modify friction behavior on Physics 2D Material 1 Answer
How to make paddle influence ball motion in brickbreaker 0 Answers
Vertical wall friction when character is falling and presses into a wall? 1 Answer
Physics 2D Frictionless 1 Answer
Physics2D simulation is not taking into acount the material's Friction 1 Answer