Collider/Trigger Problem

Hey guys,

Working on a game that involves a ball hitting a button and having the button activate something. I am already familiar with triggers.

What I want is for the ball to hit the button (have the ball enter the collider) and the have that trigger a wall to move so the player can advance. I have it all set up, but when the ball enters the collider, nothing happens.

I already have successfully used triggers earlier in this project to trigger the end of a level, so I think it should be working.

Here is the code that is applied to the button:

#pragma strict

var floor: GameObject;
var triggered: boolean = false;
var target: Collider;

function Start () {

}

function OnTriggerEnter(collision: Collider) {

	if(collision != target) {
	
		return;
	
	}
	
	triggered = true;
	
		//if(triggered == true) {
	
	//for(var i: int = 0.5455484; i < 20; i++) {
	
		floor.transform.position = Vector3(3.313264, 20.545548, -0.07298398);
	
	//}
	
	//}

}

function Update() {

}

I have already tried putting the if statement in the update function so that it will always check, and that didn’t work.

Specs:

Ball:

-Sphere Mesh Filter
-Sphere Collider (checked)
-isTrigger = false
-Mesh Renderer (checked)
-RigidBody (checked)

Button:

-Sphere Mesh Filter
-Mesh Renderer (checked)
-Sphere Collider (checked)
-isTrigger = true

Am I doing something wrong? Am I missing information?

Thanks a lot guys, you’ve already been a huge help to me.

-Silent

not sure but with such short code the mistake cant be very hard to find.
try changing the target type to Transform, and then instead of

if(collision != target) {

use

if(collision.transform != target) {

Hmm… No, doesn’t work.

Shouldn’t it be the colliders though, and not the transform?

how about

if(collision.gameObject != target.gameObject)

Still doesn’t work. Maybe the collider isn’t sensing properly?

Maybe I should just rebuild the whole collider script/entity entirely

Are you using the collision matrix to ignore some collisions?

Try to put some Debug.Log in different places of your collision detect code to see until where it’s going while the game is running.