Matt Yaple
Matt Yaple

Reputation: 65

Can't get rigidbody collisions to work in Unity3d with box colliders

so I am using Unity to create an Android game and I cannot get any collisions to work. Both objects have box colliders and one has rigidbody attached to it. When I hit play it just falls through the floor. So I instead tried to make the rigidbody object kinematic and control it's movement via transform.Transform instead of rigidbody.addforce I then made a cube in front of the character with a box collider that has "Is Trigger" checked. I then attached this script to both the rigidbody and the cube.

#pragma strict
function OnTriggerEnter ( block : Collider){

print("BA BAM!");
Destroy(block.gameObject);

}
function Update () {
if (Input.GetKeyDown(KeyCode.Escape)) {
    Application.LoadLevel("MainMenu");
}
}

but I will move the character right through the block and nothing happens!

I then decided to create a new blank scene and made two cubes. Both have box colliders. I dragged one above the other and added rigidbody physics to it. But it just falls through the other block when I hit play! Any help will be greatly appreciated!

Upvotes: 0

Views: 6809

Answers (2)

DigitalPancake
DigitalPancake

Reputation: 71

Moving the object using the Translate function will teleport the object into a new Vector3 position instead of smoothly moving it.

Also, check which Physics layer each object is set to. Then, go to Edit -> Physics to edit which Physics layer can collide with each other.

Other than that I would speculate it would due to some bug in your installation of Unity.

Upvotes: 0

Calvin
Calvin

Reputation: 4195

Triggers aren't solid, so a box with a trigger and a rigid body would fall through a solid object. Generally the object with a rigid body should not be set to trigger, and stationary volumes should be set to trigger. Besides that, I tried your code and it works correctly. Are you sure you have this script applied to the objects that are colliding?

Upvotes: 1

Related Questions