- Home /
Can I make A trigger, Trigger the OnTriggerEnter Function
So I have a Torch Light mechanic where when you shine the torch on specific points it's meant to show an object, but the Torch Light is a trigger object. This is the code I have so far which isn't working, I have also replaced the L_O_S (Line_Of_Sight) with the player object and it worked, I am getting quite confused, if anyone has any ideas on how I could go about doing this it would be greatly appreciated. the code has been put on the point of interest which is also a trigger.
public class Point_Of_Interest : MonoBehaviour
{
public GameObject Item_Dropped;
// Start is called before the first frame update
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "L_O_S")
{
Debug.Log("Object found");
}
}
}
Answer by VideoJames · May 14, 2019 at 02:29 AM
OnTriggerEnter will only activate if at least one of the two colliding objects have a RigidBody.
Most likely your player has a RigidBody, which explains why it works when you replace "L_O_S" with "Player".
I suggest adding a RigidBody component to your Torch Light, and setting Kinematic to true to prevent gravity from affecting it.
From Unity's Documentation
Notes: Trigger events are only sent if one of the Colliders also has a Rigidbody attached. Trigger events will be sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions. OnTriggerEnter occurs on the FixedUpdate after a collision. The Colliders involved are not guaranteed to be at the point of initial contact.
Your answer
Follow this Question
Related Questions
OnTriggerEnter doesnt see enemy 1 Answer
Updating a Value in OnTriggerEnter and Returning That Value Immediately... 0 Answers
How do I ignore trigger objects for collision? 0 Answers
Detect trigger touching another trigger? 1 Answer
OnTriggerEnter is not working! I have tried absolutely everything I can think of. 1 Answer