- Home /
RigidBody collision is unaccurate
Hi!
I am trying to create my first Unity game, and have encountered a slight problem.
Player object is a cube, with a rigidbody object attached to it. Rotation is locked on all axis, movement is locked on X, thus it does not rotate and only moves on the Y and Z axis.
I generate a line of 1x1x1 cubes, using the same X and Y, and incrementing Z by one each time.
My problem is as follows:
The cube seems to move "inside" of the world cubes, and thus sometime (not always, but often) it seems to collide with the corner of the next cube and thus start jumping. (If I unlock rotations it will start rotating wildly.) Resulting in small jumps like:
Is there any way to prevent this, except just locking the Y velocity to zero or less unless jump key is pressed and OnCollisionExit?
I have tried changing to Continuos, and Continuous Dynamic collision, with no difference.
I apologize if the answer is obvious, but I have looked through several tutorials and searched google, and been unable to find any answer. Perhaps I do not know the correct terminology, and thus haven't found it. Any help would be appreciated.
Thanks for reading.
Are you checking the collision in Update() function or FixedUpdate()? For physics, It's better to calculate collision inside FixedUpdate, because it's called before update.
I do not check manually, I have just created cubes which form the ground and a single moving cube which has a rigidbody component attached to it.
Answer by robhuhn · Sep 20, 2013 at 02:56 PM
have a look at my question here: http://answers.unity3d.com/questions/399064/prevent-collider-intersection.html
Answer by Owen-Reynolds · Sep 20, 2013 at 02:01 PM
This is normal. Think about all the times you've been snagged on nothing in any other game.
It's fixed by cheating one way or another. Could pull the player up a tiny bit and check off UseGravity (so she will never touch those cubes.) Or could put a thin invisible floor on top of everything. Or could give the player an (invisible) child sphere at the base to roll over those gaps. Or (and not sure if this works) make the floor cubes a tiny bit wider.