Why is my trigger collider acting like a normal collider?
I have two colliders: A mesh collider, which is just a normal collider, and a trigger collider to detect when the player is near the object and run some code. I'm using OnTriggerEnter and OnTriggerExit, but the only things in them are Debug.Logs.
My player has a rigidbody component, my object does not.
My player hits the trigger collider as if it's a solid normal collider and I can't figure out why...
too little information, show some code. For example your controller, do you do raycasts to deter$$anonymous$$e where you can move?
It's just a collider with IsTrigger marked as true. Player (movement) code currently is
void Update()
{
if(Input.GetAxis("Forward") != 0){
transform.Translate((player.transform.forward * playerSpeed) * Time.deltaTime, Space.World);
}
}
Code is private void OnTriggerEnter() { Debug.Log("it works"); }
private void OnTriggerExit() {
Debug.Log("This also works");
}
For now I have solved it simply by creating an empty with the collider and code, referencing my object.
Answer by MandMs05whyismynamealwaystakenthisisMYname · Feb 22, 2021 at 09:16 PM
I've solved it by creating a new empty with a trigger parented to the object I wanted the trigger on.
I think it was simply that the object with the trigger also had a normal mesh collider which messed with things, but I've fixed it just by making a new empty with only a trigger collider.
If you have a similar problem, try that! Here's some sample code for linking up the empty with the collider and the object you wanted the collider code on:
public GameObject yourObject;
private void OnTriggerEnter(){
[Your Code Here]
//make yourObject jump using rigidbody physics
yourObject.GetComponent<Rigidbody>().AddForce(transform.up)
}