- Home /
2D objects gets stuck on the ground/wall?
Hi!
I just noticed in my small 2D game that the objects stop on the ground. Like I have a conveyor belt and when the cubes move on it they randomly get stuck. This also happens when they slide down next to a wall. How can I fix this?
Thanks in advance
Could you try to describe your problem a bit more please? I'm not sure I got it ;)
Remember to post comments as actual comments and not answers (I have converted this one for you).
@Souk21 Sure. So basically I have a crate object. It has a 2D box collider and a Rigidbody 2D. If I place that object next to a wall that consists of multiple sprites with box colliders, it randomly gets stuck on the wall. This also happens when I have some kind of conveyor belt. It is basically a script that applies force to a rigidbody object. While the object is moving it gets stuck. I hope that explains it better!
What do you mean by "stuck"? Is it stopped? Slowed down? Does it happen with a single collider for the ground? You can put all your ground sprites in an empty gameobject and apply a box collider to it, ins$$anonymous$$d of having multiple colliders
@Souk21 When I say it gets stuck I mean it stops. In order for it to push something needs to push it. And with the wall sprites, I can't do it like that. I need all the wall sprites to be separate. It happens randomly each time.
I found the solution! Please see my post below.. It's the Box collider. Thx
Answer by ajdrew81 · Aug 11, 2015 at 06:44 PM
Try using Edge colliders on your box instead. It worked great for me. Here's where I found that out http://forum.unity3d.com/threads/rigidbody-getting-stuck-on-tiled-wall.220861/
Hope this helps!
Answer by imaginaryhuman · Mar 12, 2015 at 07:51 PM
I think it's to do with the fact that the physics engine is not 100% accurate, and that may well boil down to the fact that floating point numbers are not 100% accurate. While unity/physics is probably trying to keep the object flush to the surface, sometimes there is a tiny little bit of penetration into the surface, especially if forces are being applied or surface are moving. I believe what happens is the moving object's collider sinks into the surface just ever so slightly, enough that when it gets to the corner of a box collider (or other types also) it sort of collides against the side of that collider, and sometimes this makes the object bounce up as if it hit something, or also can make the object get stuck. It's the joins between colliders combined with slightly imprecice physics that is the problem, in my opinion. One fix I found is making your object kinematic and moving it without forces. Otherwise I guess you could program some kind of fix
in a script, like OnCollisionStay2D, making sure the object is moved up a little bit if it enters the surface?
Answer by Hanh · Aug 31, 2017 at 07:27 AM
Physics Material 2D worked for me.
- Create a Physics Meterial 2D.
- Set friction is zero
- Assign it into colliders (don't need for player)
Hope it can help you
Answer by SnStarr · Jan 19, 2015 at 06:31 PM
Sounds similar to some prototype games where if the player jumps and force is being added to a rigid body to make the player move, and he hits a wall as long as the player is holding the arrow key down there is still being force applied and he will stick to the wall until you let go of the move key. That has to do with the force being applied to the rigid body sideways is more than the force that physics gravity can overcome. Sounds to me like every once in a while the Gravity from the Physics is too much force downwards than is being applied to the rigid body sideways causing the object to "Stop" it's not really stopping, more than it's just going downwards faster than sideways so to speak so it looks like it's not moving. Either try adding more force to the object or lower the Physics Gravity from Project Settings.
I don't think it has anything to do with the gravity. So if I just had -1 it still stops. If I would add more force it would not function as I want it to. If you are interested, here's a GIF of my crate stopping on my conveyor belt.
As you can see it just stops. It always stops on that tile too. It is not different in any way from the other tiles.
Answer by alxdncn · Jul 20, 2016 at 02:27 PM
Another solution is to give the object a PhysicsMaterial2D and set the friction on it to zero. This worked for me. But depending on how you're moving this object, it might have some unintended consequences.