- Home /
Collider with rigidbody does not register collision with terrain
I have a gameobject that uses transform.Translate() to move. It has a collider and a rigidbody, but it never detects collision with the terrain. I can see it pass through the terrain, but with this code
void OnCollisionEnter(Collision col) {
FindRunAwayLocation(col.contacts[0].point);
Debug.Log("oof");
}
It does not register the collision. Any answers? Thanks
Answer by donutLaserDev · Mar 22, 2018 at 02:21 PM
Well, first thing is, is the rigidbody dynamic? If so, you shouldn't use transform.Translate to move it. Change rigidbody's velocity or use forces (e.g., rigidbody.AddForce) to move it. It is possible that from the perspective of physics engine, the game object did not move anywhere due to you moving it via transform. If the rigidbody is kinematic, it will not collide with static colliders as shown in the collision matrix on this page: https://docs.unity3d.com/Manual/CollidersOverview.html
I ended up making my rigidbody not kinematic and putting
rb.position = transform.position;
in my update method. Thanks!
Answer by BigPha · Mar 22, 2018 at 05:03 PM
Check if you don't mix collider2d and colllider, if you terrain has collider2d on it and you rigidbody has collider, the collision will not be registered.