- Home /
Cube player not sliding smoothly on floor made from prefab cubes
I've got a cube with rigid body and box collider as my player. The floor is generated from a script which instantiates a handful of objects from a prefab 1x1x1 scale cube which also has both rigid body and box collider. I'm adding force to the player cube to slide it across the floor made of the prefab cubes. While the floor looks (visually) to be smooth, there must be a seam between the cubes... the edge of the player cube catches sometimes (not at each seam between floor cubes, only about 1/3 of the time from my estimation from testing in the Game view), causing the player cube to register OnCollisionExit and the cube rotates forward a bit, then almost immediately OnCollisionEnter when it rotates back to starting rotation as it continues to slide across the floor.
Any ideas what may be causing the floor to not be as smooth (in the physics world) as it appears to be on-screen? I need the floor to be smooth so there is no OnCollisionExit registering (or unwanted rotation) as the player cube moves from one floor cube to the next. I'm using a script to generate and recycle the floor cubes.
This is a known phenomenon; just a quirk you'll learn to live with. When two colliders are mathematically adjacent, they overlap and can cause this issue. Easy fix is to try reducing the size of the colliders; try (0.99).
On your advice, I tried using 0.99 for the x/y/z scales on the prefab's box collider, still no luck (same thing happening). Any other ideas? It's still registering a collision when transitioning from one prefab floor cube to the next.
Answer by Fanttum · Mar 15, 2015 at 03:53 PM
I'd try using a sphere or capsule colder instead of a box collider. (just make sure to lock rotation)
This makes it so your cube will then "roll" over any rough surface.
Fanttum, tried this after your comment was received. While it helped the character not to rotate and tumble when it hits a seam between prefab cubes, it did not fix the collisions between the player and the floor prefab cubes, so it's still throwing OnCollisionEnter and Exit each time it moves to a new floor prefab cube. Any other ideas? Attached is a screenshot of player inspector settings and the console showing the OnCollisionEnter/Exits being called repeatedly as the player moves across the tiles.
Hmmmm, not sure any way to really fix that. Its got touch something... Is there a reason it shouldn't be entering the floor? $$anonymous$$aybe you could take off UseGravity and just have your Cube float slightly over everything and that might solve all your problems unless you need that for other things.
Previously, was rotating the cube as soon as it left the floor (OnCollisionExit), although I decided to switch to a sphere for the player because of this issue. Now, with the sphere, it seems to move correctly across the floor without the unwanted bumping and rotating.
Also, I removed the OnCollisionEnter/Exit calls, and substituted a Raycast in the down direction from the sphere player to deter$$anonymous$$e if touching the floor, and this seems to be working better.
Thanks for your help!
Answer by brandonalbers1 · Mar 28, 2020 at 03:02 PM
I had the exact same problem so I applied a physics material to my object that had no friction. I hope this helps someone out!
Your answer

Follow this Question
Related Questions
OnMouseDown() cube face? 1 Answer
Face detection 1 Answer
How do I add a texture to a cube (yes I know I'm a scrub)? 1 Answer
Custom Mesh UV Problem 1 Answer
Hiding faces of a cube ? 1 Answer