- Home /
Collision Detection between instances of a prefab
I am current trying to implement some simple projectiles (fireballs) in my game in Unity. As it currently stands I am creating a rigidbody instance of my fireball prefab before applying a force to it in the direction of my target. A wizard casting a fireball spell essentially:
Vector3 target = targetWizard.transform.position - staff.position;
Rigidbody fireball = (Rigidbody)Instantiate(baseFireball, staff.position, staff.rotation);
fireball.AddForce(target * speed);
I have two wizards in my scene that can both shoot these fireballs at each other and I have been trying to set up my collision detection logic so account for both these scenarios:
1) Should the two fireballs collide with each other - something happens 2) Should the fireball hit the opposing wizard - something happens
Currently my fireballs both have Rigidbodies and Box Colliders with a simple script attached that has the onCollisionEnter or onTriggerEnter functions with simple debug messages within each.
void onCollisionEnter(Collision other)
{
Debug.Log("Collision");
}
void onTriggerEnter(Collision other)
{
Debug.Log("Trigger");
}
I have been unable to work out a situation where any of these functions are called on my fireballs.
Presently when they hit each other or a wizard (it has a rigid body and capsule collider) they show that physics are operating on the impact but neither function above is called.
I've tried the scenario where the Is Trigger is checked but this just leads them to pass through everything without no function called either.
I have tried to read other answers and reference material but have met with no success and I am currently at a loss as to why I cannot get this to work.
You are calling those functions OnCollisionEnter and OnTriggerEnter right? With capital 'O's
Your answer
Follow this Question
Related Questions
Help On Checking OverLaping in instantiating 0 Answers
Instantiate GameObjects inside a collider 1 Answer
contuouse collision detection malfunction 2 Answers
how to prevent an gameobject of instantiating if theres an collider where it is supposed to collide 1 Answer
Freeze Position + collision? 0 Answers