- Home /
Colliders Events
So, I have this prefab (A simple BoxCollider) that I'm instantiating near an object. What I'm trying to do is that, when that object gets instantiated, check for a collision with certain objects. To accomplish this I tagged those objects with "Character".
This prefab has a script with just an OnCollisionEnters event, beside the empty methods update and start.
void OnCollisionEnter(Collision collision){
if("Character" == collision.gameObject.tag){
Destroy(collision.gameObject);
}
}
But, for some reason, when the prefab spawn, if there is a Character tagged gameObject(this object has a collider and a rigidbody (non-Kinnetic)) colliding, the event doesn't trigger.. but if I move this gameObject, it does. Also, I have the ThridPersonCharacter asset on my scene, tagged with Character too.. if I replace the position of this ThirdPersonCharacter with the position of my previous gameObject and run the scene, the event does trigger as soon as the prefab spawn.
Why is this happening and what can I do to solve it? I need that as soon as its instantiated, the event triggers, not after the gameObject is moved.
Thank you!
Answer by Neamtzu · Apr 09, 2015 at 10:25 AM
From the documentation, it seems your character regidbody is in sleep mode. Try to add a rigidbody on your other object or call the wakeup function on your character.
It worked!! thank you for the help... though i tried to wake him up upon start and it didn't. I had to put it on the Update function :/
public class $$anonymous$$eshWakeUp : $$anonymous$$onoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
GetComponent<Rigidbody>().WakeUp();
}
}