Search Unity

Need help stopping the enemy hitting target

Discussion in 'Scripting' started by sim18, Jan 23, 2014.

  1. sim18

    sim18

    Joined:
    Oct 15, 2013
    Posts:
    36
    Hi all,

    I will try and make myself clear:

    I have multiple enemy zombies walking around, I have added a Raycast so that if the zombie hits any object or other zombies they will move in a different direction.

    If my cargoes within a certain distance to the zombie, the zombie will turn and walk towards my car. If I hit the zombie with my car the zombie quickly turns into a ragdoll thus giving the impression its just been hit.

    My problem is that if my car is not moving, the zombies all walk towards it looking for the "target" that is in the center of my car, so as soon as the zombie touches the box collider it thinks its been hit and turns into a ragdoll.

    I have tried setting it so that when the zombie is near the target but not quit hitting the car then stop. But this doesn't work because if a zombie walks from the side they are different distances. I have no idea how to make the zombie stop before hitting the collider to turn it into a ragdoll.

    I basically want the zombie to walk to the car... stop just before the box collider and attack.

    I have tried another box collider, I tried using a raycast, but it just keeps moving towards the centre.

    Thanks for any help
     
  2. softwizz

    softwizz

    Joined:
    Mar 12, 2011
    Posts:
    793
    You could use a value in the car script like ismoving = false or true depending on what its doing.

    In the zombie script have it check this value as soon as it touches the collider and then decide on the zombie actions.

    something like.
    Code (csharp):
    1.  
    2. when zombie hits car collider
    3. {
    4. check if car ismoving;
    5. if (car ismoving)
    6. {
    7. ragdoll zombie;
    8. }
    9. else
    10. {
    11. attacking zombie;
    12. }
    13. }
     
  3. sim18

    sim18

    Joined:
    Oct 15, 2013
    Posts:
    36
    Thank you!

    I will try this :)