Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Collision Not Work. Help!

Discussion in 'Editor & General Support' started by paramitaUni, Oct 11, 2014.

  1. paramitaUni

    paramitaUni

    Joined:
    Oct 11, 2014
    Posts:
    7
    Hi all, I just got a problem when I implemented magic hit to monster in my level. Here is what I did:

    1 : When I tap spell button, I want to player shot a magic arrow toward the monster. Here is my code:

    public Transform effect_common;

    // play animation attack01
    gameObject.animation.CrossFade ("attack01", 0.1f);
    gameObject.animation.CrossFadeQueued ("idle", 0.3f, QueueMode.CompleteOthers);

    // shoot magic arrow
    Vector3 pos = transform.position + transform.TransformDirection(Vector3.forward*1) + transform.TransformDirection(Vector3.up*2);
    Instantiate(effect_common, pos, transform.rotation);

    2 : I bought ""Shuriken Magic" Effect Pack",and use one of the prefab VFX "fireBallbase" as the magic arrow. (Maybe you guys know this asset and use it already, that's great look!). And assign the fireBallbase to my variable "effect_common".

    3 : Then I added component "Box Collieder" and "Rigibody" to my monster object. Also, I added component "Box Collieder" and "Rigibody" to the prefab "fireBallbase" under url -"Assests/ShurikenMagic/Projectile/fireball". I have checked "Is Trigger" at all "Box Collider".

    4 : Last step, in the script of the monster, my code is :
    void OnTriggerEnter(Collider mCollider)
    {
    if(mCollider.gameObject.tag=="missle")
    {
    Debug.Log("monster hit!");
    }
    }

    5 : Now, the fact is, from the scene view, I can see exactly the magic fly across the monster, but the collision did not happen. The console did not print anything when the magic hit monster.

    So, could you guys can help me point out what's the reason. Did I make something wrong, or miss something. Thanks a lot!
     
  2. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,489
    Is the prefab "fireBallbase" tagged "missile" as you are checking for in your code? Get rid of the tag check and just see if you ever get any trigger enter events.

    Make sure the fireBallbase prefab has the Rigidbody and BoxCollider on its root object.

    Take a look at the Collision Matrix at the bottom of this page and make sure your colliders would be colliding based on their settings.
     
  3. paramitaUni

    paramitaUni

    Joined:
    Oct 11, 2014
    Posts:
    7
    Thanks for your help, I'll check this article for more understanding!