- Home /
Problem with OnTriggerEnter()
Hey guys! I'm making a Doom-style FPS (meaning the Y-axis is locked). Anyways I want the raycasts from shooting to aim up or down based on the enemy the player is looking at. The best workaround i could figure out for this is to attach a trigger box collider to an empty object on the camera that determines the relative Y angle to the enemy when AI enters the box. I'm having trouble getting the OnTriggerEnter() to call (whereas OnTriggerExit() works just fine). Here's a visual example:
There is a collider and rigidbody attached to ALL AI
The trigger box attached to the camera is large enough to completely fit the AI
The script is attached to the same game object as the trigger
They're all on the same layer (which is set to respect physics on collision with itself)
Here's some of the script:
private var colliderCount = 0;
function OnTriggerEnter(hit : Collider){
Debug.Log(colliderCount + "registered");
if (hit.transform.tag == "AI") {
colliderCount++;
Debug.Log(colliderCount);
}
}
function OnTriggerExit(hit : Collider){
if (hit.transform.tag == "AI") {
colliderCount--;
Debug.Log(colliderCount + "registered");
}
}
I'd be really happy if someone could help me figure it out (or provide a better workaround than the one I'm using), and I'd be happy to provide pictures of my kitten as a 'thank you'!
Could you elaborate more on your problem. It is not entirely focused and are introducing multiple issues.
Is it simply an object entire your collider is not trigger the event or a problem with shooting a raycast at an enemy location?
Answer by AmarokStudios · Jul 23, 2014 at 11:59 PM
On the collider for the trigger, do you have "Is trigger" ticked?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Why is my script not working like it should 3 Answers
Can't figure out how to use multiple triggers in single scene 1 Answer
how to go through platform like bananakong? 1 Answer
Damage rate HELP 1 Answer