- Home /
[3D] Character stuck between cubes.
My character get's stuck between cubes (that i use as platforms) when walking, just at the edge between them and the both cubes are side by side with no space in between.
My character has a rigidbody with freezed rotation axis.
I tried box collider, sphere collider, capsule collider... none of them seems to be the problem. I also tried adding a sphere colliders at the bottom of the box collider but nothing.
Cubes are box colliders with scale of (20, 1, 20).
EDIT - Here is a screenshot, there are the two cubes side by side and the capsule collider stuck between them:
EDIT2 - Rigidbody
Edit3 - Movement Script:
Vector3 dir = movementJoystick.inputDirection;
Vector3 forward = mainCamera.transform.TransformDirection (Vector3.forward);
forward.y = 0;
forward = forward.normalized;
Vector3 right = new Vector3 (forward.z, 0, -forward.x);
float h = dir.x;
float v = dir.z;
dir = h * right + v * forward;
body.position += dir * (Time.deltaTime * walkSpeed);
SOLVED: It had to do with OnCollisionEnter and OnCollisionExit. I was using a bool of grounded to know if the character was or not. Seems traspassing the edge of the collider called the function making grounded go false.
Then i have specified that if my character is not grounded he won't be able to move. So that whas the problem.
So from now on i will use raycasting. Thanks to everyone that helped me!
The capsule collider should work just fine. Are you sure you didn't accidentally freeze the y-axis?
X, Y, Z rotation axis are freezed but not movement ones.
I tried playing with them and the result is the same. Capsule collider gets stuck between two cube colliders. I even have the character floating at the start to ensure he isn't under the surface.
can we have a screenshot of your rigidbody component? and your movement script?
Here is the problem, the character traspasses the edge but gets stuck there in between:
Answer by IvanHTN · Jun 22, 2016 at 09:26 PM
Okey i feel ashamed, it had to be with my grounded collision script.
On leaving a collider it declared grounded as false and i have defined that something that is not grounded can't move at all.
So when the character was reaching the edge of the first cube it goes directly to grounded = false and then is unable to recognize fast enough the second cube for getting the grounded = true.
Answer by seckincengiz · Jun 22, 2016 at 02:42 PM
Try using one big box collider for both cubes. Sometimes(if your object too small) unity can't response fast enough to detect collision. You can also change that response time( time settings / Fixed Timestep). Also change your rigidbody component's Collision Detection as Continuous Dynamic. And make sure your collider component's "Is Trigger" option unchecked. If problem still exist check your physics settings (Layer Collision Matrix). These are the basic rules that you should look first when your colliders act weird. But in your case you should also check your script again. Disable the script and try again. Your script could be the problem.
Using 1 collider solves the problem but i discovered that this also happens when i go to a corner of walls, character get's stuck between colliders.
I checked everything else u mention except the Layer Collision $$anonymous$$atrix which is something i don't understand, here is my configuration: Is there something wrong?
I'm going to check if there is something wrong with my script.
It looks like your collision matrix (http://docs.unity3d.com/$$anonymous$$anual/LayerBasedCollision.html) is not the problem here. Did you try unfreeze rotations? $$anonymous$$aybe the force which is trying to rotate your object is also push it because of your object's fixed rotations.
You said that one big collider solved your problem. It means that your script may not the problem. Try to scale size of your collider. For example (20,1,20) --> (20,10,20)
if it doesn't work try to apply your script another collider and try again. $$anonymous$$aybe you changed something on that object and you don't remember.
Answer by TCROC · Jun 22, 2016 at 04:06 PM
Have you tried making your collision detection continuous or continuous dynamic? It is normally used for detection collisions between fast moving objects like bullets, but it could do the trick for you.
Already tried, nothing. It seems it's something related to my script, trying to find out what it is.