OnTriggerEnter Trouble

function OnTriggerEnter (other : Collider) {
	if (other.name == "RaceCraft") {
		if (PlayerControl.checks == 6) {
			PlayerControl.lapsdone ++;
			LapCounter.laps += 1;
			PlayerControl.checks = 0;
		}
	} else if (other.name == "RaceCraftRed") {
		print("yay");
		RedControl.lapsdone ++;
	} else if (other.name == "RaceCraftYellow") {
		YelControl.lapsdone ++;
	} else if (other.name == "RaceCraftGreen") {
		GreControl.lapsdone ++;
	} else if (other.name == "RaceCraftLavender") {
		LavControl.lapsdone ++;
	}
}
function Update () {
	if (LapCounter.laps == 6 || Input.GetButton("Abort Race")) {
		Application.LoadLevel("LevelSelect");
	}
}

None of the triggers here will register except for RaceCraft, making it so that when Green, Red, Yellow, or Lavender cross the finish line it completely ignores them. All of the crafts are set up the same way as the first…

Do they all have Rigidbodies attached?

Yeah. Every last one.

Maybe there is a conflict somewhere

I would suggest using Debug.Log(other.name)

Have you tried it with tags? (other.tag)

Grtz,
kaaJ

As we all crossed the line, the Debug.Log printed “RaceCraft”, but none of the others.

And the GameObjects with the Collider components are called “RaceCraftRed”, etc? (that is, you have the colliders on the correct objects)

Are all the colliders marked as Triggers?

This doesn’t matter. Only the Collider on the object to which this script is attached needs to be a trigger.

Muriac, they all have colliders set up on them, the Finish Line is a trigger, and they’re all named correctly.

Obviously if the one is working and the others aren’t, it’s some sort of difference in the setup of your craft. Am I correct in assuming that RaceCraft is the player’s craft, and the others are AI-controlled opponents?

Yeah, RaceCraft is the player and the others are AI. The only thing different at all in their setup is the script (RaceCraft has “PlayerControl”, RaceCraftRed has “RedControl”, etc…). So it must be something in the enemy control scripts that’s causing the problem…

var target : Transform;
var last : Transform;
var accel = 2;
static var percent = 0.0;

static var lapsdone = 0;
static var place = 0.0;
var increment = 0.0;

function FixedUpdate () {
	rigidbody.drag = increment;
	transform.rotation.x = 0;
	transform.rotation.z = 0;
	
	if (rigidbody.angularVelocity.magnitude > 0){
		increment = 1;
	}else{
		increment = 0.0;
	}
	
	if (Physics.Raycast (transform.position, Vector3.down, 1.5)) {
		rigidbody.AddForce (Vector3.up * 7);
	}
	if (target.collider) {
		var targetPoint = target.position;
 		var targetRotation = Quaternion.LookRotation (targetPoint - transform.position, Vector3.up);
 		transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 2.0);
 		var look = targetPoint - transform.position;
 		look.y = 0;
 		targetRotation = Quaternion.LookRotation (look, Vector3.up);  

	}
	var thrust = accel + (increment * 15);
	rigidbody.AddRelativeForce(0, 0, thrust);
	var d1 = Vector3.Distance(transform.position, last.position);
	var d2 = Vector3.Distance(transform.position, target.position);
	var lerpVal = (d1/(d1+d2));
	percent = Mathf.Lerp(last.GetComponent(Waypoints).progress, target.GetComponent(Waypoints).progress, lerpVal);
}

I don’t see anything in that code that would cause the behaviour you’re seeing. The most reliable way to get triggers to detect things is to handle all your movement by pushing rigidbodies around, which is what you’re doing.

You might try adding the following line to the beginning of your OnTriggerEnter() function:

Debug.Log(other.name + " entered lap counter " + name);

When I put that in, it only registered for the player controlled craft once again… I’m messing around with it, but I’m seriously stumped.

Erm… I figured it out… I’m almost embarrased to admit it. :stuck_out_tongue: The trigger they were to be entering was positioned and sized in a way that they were all avoiding it, even though I was hitting it. :sweat_smile:

At least the answer makes sense! :slight_smile: I feel your pain, though. Breaking down what you take for granted can be difficult.