Trouble with collison and trigger's
So here's my problem. I have a sphere with a collider and I want it set up so that when the player walks through the sphere it instantiates an object and the object plays animation that basically makes the object appear to be falling on the player. Then I want a collider in the object and to make it so that if the object actually touches the player then they get deleted but if it doesn't then they can continue.(I'm gonna make it load a different scene if it touches them but this is for testing purposes). Now the way I have it set up is that way exactly with two scripts for execution. One inside the sphere to instantiate the object and another inside the actual object to detect if the player is touched by the object. The problem I'm facing though is that the player get's deleted as soon as they touch the sphere and has no time to run from under the object. I applied root motion to the animation( just in case that information is relevant). Can anybody tell me what I'm doing wrong here?
here's the scripts
inside the sphere;
using UnityEngine;
using System.Collections;
public class Squash : MonoBehaviour {
public GameObject crush;
void OnTriggerEnter(Collider Other){
GameObject crushClone = Instantiate (crush);
Destroy (crushClone, 2.0F);
}
}
inside the object:
using UnityEngine;
using System.Collections;
public class Death : MonoBehaviour {
void OnTriggerEnter(Collider Other){
if (Other.tag == "Player") {
Debug.Log (Other.gameObject.name);
Destroy (Other.gameObject);
}
}
}
Answer by justinyeh · Oct 21, 2016 at 12:51 AM
OnTriggerEnter is only for when a collider(not trigger) touch the trigger.
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter.html