- Home /
2018.2.17 OnTriggerEnter2D not working
I've doubled and tripled checked the spelling of the function. My OnTriggerEnter2D is never being called. I've tried changing the Rigidbody to Kinematic and Dynamic with no change.
Here is the inspector showing two objects with Box Collider 2D. The player also has a Rigidbody 2D.
Player: Grass: Grass Script:
using UnityEngine;
using System.Collections;
public class LongGrass : MonoBehaviour {
public BiomeList grassType;
private GameManager gm;
void Start () {
//gm = GameObject.FindGameObjectWithTag("GameManager").GetComponent<GameManager>();
}
void Update () {
}
void OnTriggerEnter2D(Collider2D col)
{
Debug.Log("HERE I AM");
}
}
Following a tutorial (see code), the player moves with Vector3.Lerp. Which maybe doesn't trigger?
What am I missing? Why isn't the trigger calling the function?
That should work. Have you tried to set the rigidbody collision detection to continuous or manually move the player into the grass in the scene view to see if it triggers? It could be because the player is moving through the grass collider too quickly and it doesn't register that frame. EDIT - Just noticed you have disabled simulated on the Ridigbody, note the warnings underneath. I'm guessing you are using an old tutorial which didn't have that option
Answer by WarmedxMints · Mar 03, 2019 at 12:11 AM
Check simulated on the Rigidbody. You can set the gravity scale to 0 if need be.
Your answer
Follow this Question
Related Questions
Trigger 2D (another gameObject) 4 Answers
BoxCollider2D, Trigger not working 1 Answer
Problem with 2D Collider Trigger 1 Answer
Apply Rigidbody/Colliders on EventSystem or Prefab Itself? 0 Answers