- Home /
Does OnTriggerStay don't detect a collision with a non-trigger collider?
I have a player that can move and has a collider and a rigidbody. I have an interactable object that has a trigger collider and a rigibody too. The object has this script attached:
public class Interactable : MonoBehaviour
{
private void OnTriggerStay(Collider col)
{
Debug.Log("Inside the range");
if (Input.GetKeyDown(KeyCode.E))
{
Debug.Log("Interacted with an object");
col.gameObject.GetComponent<StateManager>().Interact();
}
}
}
Why isn't the function called when player walks inside the trigger that has that script?
I have also tried with OnCollisionStay but still doesn't get called. The player is in the layer "Player" and the object in the layer "Interactable", and they have collisions enabled in the project settings.
You have another problem in your code, Get$$anonymous$$eyDown should only be called inside Update or LateUpdate. As trigger events are called inside FixedUpdate, you risk missing some inputs, and getting some others twice.
Answer by unity_2_3_VXKGFGtKtg · Oct 24, 2019 at 03:21 PM
what actually are you trying to do?, i can't see where are you telling object to do something when is in trigger or even detecting if it's trigger, i am using OnTriggerStay to for ground detection but like this. i am asking if the object that my player collide with is trigger or not and it's tag
void OnTriggerStay(Collider other)
{
if (!other.isTrigger && other.gameObject.tag == "Ground")
{
characterControl.IsGrounded = true;
characterControl.Dowalljump = false;
}
}
Your answer
Follow this Question
Related Questions
get only one colliding body 3 Answers
How do I use colliders and/or triggers to end the game? 1 Answer
Trying to make object turn red OnTriggerEnter 0 Answers
Gameobject not detecting collison from other Box Collider 2D [SOLVED?] 2 Answers
How to single out specific colliders from another object 1 Answer