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

Throwing weapon that doesn't fall through ground

Discussion in 'Scripting' started by Deleted User, Jun 24, 2017.

  1. Deleted User

    Deleted User

    Guest

    Hello I am trying to create a knife for my character to throw. However I want it to be a trigger so it can go through enemy colliders and destroy them but at the same time I want it to be able to detect the floor collider and not fall through, allowing it to be used again. How would I do this? Can I have one collider with different reactions to different colliders or do I have to place 2 colliders on it, one that is a Trigger and one that is not. Thank you for your help!
     
  2. MilKID

    MilKID

    Joined:
    Jan 8, 2017
    Posts:
    16
  3. Deleted User

    Deleted User

    Guest

    Sorry Dx I still can't seem to get it to work. If I use the collision matrix and uncheck the player tag then it ignores them and I cant detect anything. If I turn off the plane, then it falls down through the ground/ I think I underestimated how difficult this weapon would be. So basically its a knife that you can throw and pick back up and throw again. I assume it has to have a Trigger Collider so it can go through other enemy colliders and destroy them but if I make it a trigger then it falls through the ground. Also if I place a on trigger enter command and tell it to look for a player tag then it destroys my character when I go over the item to pick it up. I'm still new to unity so any type of advice would help. Thank you MilKID for your help earlier.
     
  4. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    One cheap band-aid solution to add to what you've done so far is to have a child object on your enemy with a trigger collider, but with a different collision layer from it's parent which is able to detect your knife projectile. It however requires this child object to communicate to its parent that a knife has touched it. This solution will work but is horribly messy, fine for a prototype but I wouldn't recommend using it long term.

    If your enemy characters use trigger colliders instead that would be the far easier solution, although that depends on your game's needs.

    One method, though I haven't tried it myself, might be to change the trigger property of the knife's collider based on what it has hit. It would start off as a trigger, but switches to not being a trigger upon triggering on anything other than enemies.
     
  5. Deleted User

    Deleted User

    Guest

    I never considered having a trigger change the collider type. That would fix the knife falling through the ground issue but wouldn't making the enemy use a trigger collider not cause them to fall off the map ?
     
  6. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    Like I said, it depends on the needs of your game, none of which you have mentioned. If it was topdown, gravity is no issue.
     
  7. Deleted User

    Deleted User

    Guest

    Oh my apologies, Its uses gravity and is a 3rd person fighting game. However the good news is I worked it out! thank you all of helping me !!