- Home /
Objects stops if it lands in between two colliders
I am building an infinite runner game in which you are a cube that can move left, right, and jump. If I jump and land in between two colliders it stops like if it collided even though all the floors are the same height and there is no space in between them.
I have tried putting physics material with 0 friction to both the cube and the floors, changing the Default Contact Offset to 0.001, and even adding a sphere collider instead of a box collider but that didn't work either.
The Code for the cube is this.
using UnityEngine;
using System.Collections;
public class charController : MonoBehaviour {
Rigidbody rig;
Vector3 vel;
// Use this for initialization
void Start () {
rig = GetComponent<Rigidbody>();
Physics.gravity = new Vector3(0,-60,0);
}
// Update is called once per frame
void Update () {
vel = rig.velocity;
vel.z = 10;
if(Input.GetKey(KeyCode.RightArrow)){
vel.x = 10;
} else if(Input.GetKey(KeyCode.LeftArrow)){
vel.x = -10;
} else {
vel.x = 0;
}
if(Input.GetKeyDown(KeyCode.Space)){
rig.AddForce(new Vector3(0,500,0));
}
rig.velocity = vel;
}
}
Answer by AlwaysSunny · May 13, 2015 at 11:16 PM
This is just a fact of life working with PhysX. Unwanted reactions may occur at seams between colliders. Enforcing a tiny gap between environment colliders can treat the symptoms, but it isn't a cure. Research and follow all associated "best practices" to ensure you're doing everything possible to mitigate the issue.
Round colliders (circle, sphere, capsule) often do not experience this issue, or at least operate properly in a much broader range of scenarios. Most "infinite runner" games likely use such a collider, if they use a physics simulation at all. My guess is that most do not.