Articles Blog

Survival Shooter Tutorial – 4 of 10 : Adding Enemy one – Unity Official Tutorials (new)

Survival Shooter Tutorial – 4 of 10 : Adding Enemy one – Unity Official Tutorials (new)

The next phase we’re going to go in to is to create our first enemy. We need our enemies in the game to damage the player, we need them to follow the player, but in this particular one we’re just going to create the first enemy and make him follow you around. So let’s get on with that. As before with the player in the Models folder in Characters you will find there are some models. One of those models is this lovingly created zombunny, which looks something like this. And what we’re going to do with that is to place him directly in to the scene and then start working with him in a similar way that we did with the player. As usual I’m just going to quickly hit Save just so I don’t loose any work if we get a crash and then I’m going to drag my scene view around and this bit really doesn’t matter where we place him because we’re going to spawn him later on I’m going to use dragging from the project window and you can see that it snaps to the environment or whatever I happened to place him on to. I’m just going to drop him near the player somewhere like that. Then when we shoot this bunny we’re going to have stuff kind of fly out of him. We’ve created for you a particle system to do just that. In the Prefabs folder you will find a HitParticles prefab. So like we said before prefabs are a way of storing something that you’ve already setup and we did exactly the same thing, we’ve created this HitParticles, and what we need to do is apply this to the Zombunny. In Unity all game objects that you put in can have a hierarchy. The Zombunny has a child object which is it’s mesh, it’s kind of outline but it also has a parent and we want to drag drop this particle system on so that it’s attached to the parent. So what I’m going to do is select my Zombunny and I’m going to drag and drop HitParticles on to the parent Zombunny so that when we expand it we’ve got Zombunny, the actual object itself and we’ve got HitParticles. And basically all this is doing, if I select my HitParticles now, is creating this little puff of stuffing. I can see that because I’ve got that game object selected the scene view shows me the particle effect overlay and you can see it’s creating a puff of fluff that’s coming out of him. This particle system, we didn’t want to get bogged down too much with these various settings but we’re basically using a texture which is applied to this to just fire out a little emission of those. Again we want to detect whether this is something that we can shoot at, so similar to how we detected whether we can turn to face a particular way by isolating the floor on to a floor layer this Zombunny is going to be on a shootable layer. So with the Zombunny parent selected make sure you reselect the parent, go to Layer at the top of the inspector and choose Shootable. Set that to shootable and then it’s going to ask you if you would like to changing the children. Basically all this is saying is do you want them all to be on the same layer, this child objects, say yes, change the children. A quick note, the environment that you all dragged in to the scene at the start is also on the shootable layer, so that means that when we later give the layer a working gun you can hit the environment as well. We’ve done that, and then we basically want to setup the Zombunny in a similar way to the player, so we want him to have physics, we want him to have a physical presence in the world so we’re going to do some similar things that we did before. The first one of those we’re going to do is to add a rigidbody component. Just to give you a different way of doing things we’ve previously used the menu but you’ll notice that this is actually a search field. So I’m just going to type in Rig and I go straight to rigidbody, I can hit return to add that. I’m just going to make that expanded so that I can apply some settings. Again, drag an angular drag should be set to infinity, so I’m going to type in INF, hit return, and it should change to capitalised Infinity. And the constraints are exactly the same. We want them to be able to rotate only in the Y axis, we want them to only be moving in X and Z and frozen position Y. Your constraints should look like this. Freeze position Y, freeze rotation X and Zee. In order to actually give this physics object a boundary we’re going to put in a capsule collider, the outline of it’s physical shape. I’m hitting Add Component one more time and then I’m going to type in Cap for capsule collider and the settings for it are Centre value of Y 0.8, and a height of 1.5. So it should look like this. We need this character to attack the player so this bit’s going to be slightly different to how the player was setup. The capsule collider is there to give the character a physical presence but what we want to do is to give him the ability to detect the player We’re going to use one more collider to do that and we’re going to use a trigger collider for this purpose. So we’re going to Add Component one more time and we’re going to say SPH, sphere collider. Hit return. You can also go to Add Component – Physics Sphere Collider, but that’s just a short way of doing that. A trigger is something that doesn’t have a physical presence, it’s a collider, which means you can check when something’s intersecting it, but it doesn’t have a physical presence so we can just walk straight through it. So we check the Is Trigger box and then if we just have a look back at our bunny very briefly at the same window you can see that by default it’s set at the origin of this, which is at it’s feet. So we’re going to set the centre Y to 0.8 and the radius also to 0.8. What you’ll see is that if I just expand my capsule collider again it’s slightly further out than the capsule collier is, the reason being that we want to detect the player within the bunnies reach. So we want it to bump in to stuff but we want it’s reach to be able to harm the player so we make that sphere collider slightly bigger, we make it a trigger so that it’s not actually going to bump in to anything, that’s how we’re going to detect the player. Again with triggers the actual interactions within a scene is not what we use a trigger for. More importantly a trigger, when anything collides with a trigger or goes in to a trigger a function is called when you have a script attached that says ‘hey, something touched that trigger’. And that’s when we write our individualised code that’ll be like ‘okay, something touched that trigger’. It’s interactions in the scene view are not what we’re interested in, we’re actually interested in the behind the scenes interaction we get to write with our own code. Finally the last thing we’re going to do to complete the Zombunny is just add an audio source so I’m going to type in Audio, I’m going to scroll down, I can use my arrow keys in this Add Component menu and I’m going to use return to choose Audio Source. This thing is just to allow him to make a sound when he gets hurt and then we’re going to make that the default sound clip as well. As before, using circle select I can just click and choose Zombunny Hurt, it’s the very bottom one from the list. I can double click it to assign and close the window. As before we don’t want it to make the sound so we’re going to uncheck play on awake. We obviously don’t want that to loop or anything so we’re going to leave that there. Next we need to make the guy actually follow the player so in Unity there’s a system called Nav Mesh. In Unity Window – Navigation is what you need. Window – Navigation. That should automatically dock itself next to the inspector. If it doesn’t that’s a great place to put it, so drag and drop that tab next to the inspector on the right of your interface. We’re going to reselect the Zombunny and go back to the inspector. The navigation panel is there for us to setup our level. We’re going to setup our Zombunny first and then go back and setup the level. With our Zombunny selected I’m just going to close some of these by collapsing them up to give us more space to look at. I’m going to add something called a Nav Mesh Agent. Like I said there’s a system called Nav Mesh which is used for a simple AI in Unity and what it means is you can do a process called baking, which is to specify which parts of the level are navigable. And then you have something called an Agent which is something that’s going to traverse that, or move over that environment. The Zombunny is something that’s going to do that. We are going to give it a Nav Mesh Agent Component. You can see that it has an outline here similar to a collider and we’re going to set a more appropriate default of 0.3. 0.3 in radius. We’re going to set the speed to 3 by default and stopping distance to 1.3. We’re going to set the heigh, which is slightly lower down to 1.1. Because it’s easier to see these settings on the powerpoint I’m just going to switch over to that. So we’ve added a nav mesh component. The radius is 0.3, the speed is 3, stopping distance is 1.3 and height, a few properties down is 1.1. It should look like what we have in Unity. If you recall for the player we’re moving the player using physics, but we’re not doing that with the bunnies themselves. The nav mesh agent is actually what is moving. Just keep that in mind. We’re not actually going to be using forces with the bunnies, instead the nav mesh agent is going to pick and follow the targets automatically while also avoiding obstacles and things like that, and that’s what Will meant when he was talking about AI it’s AI pathfinding. What I wanted to point out as well and you guys don’t need to do this so just watch, the environment is already prefabbed. We put colliders on to everything so you can see that the player could bump in to all of these objects. We used primitive colliders for performance reasons to make it all work nice and neatly. What you should also note about that is there’s a checkbox up at the top here called Static. That’s checked and that means that Navigation Static is also checked. So what that means is that all of the things we’ve specified in here as being a navigable space are going to be included when we bake the nav mesh, when we create this navigable area. What I want you to do now is to go to that navigation window again and we’re going to switch over to the Bake tab, the middle one of the three, and there we have some settings that we’re going to put in there. The radius of the nav mesh is approximately how near to a wall an agent can move so we’re going to have multiple types of enemy in this so we’ve got some Zombunnys, Zombears and some Helephants. Now Helephants are a lot bigger so we need to compromise with the radius of the nav mesh. Normally you’d want to have nav mesh agents and nav meshes with the same radius but since we’ve got different size agents we’re going to compromise and make the radius for it 0.75. Likewise this height is a compromise, we have Zombunnys which we made 1.1 in height. The Helephants are going to be a lot bigger but we’re going to make our height a compromise between the two, we’re going to give it 1.2. But normally if you’ve got one type of agent and they’re all the same give the radius the same as the nav mesh agent and the height the same as the nav mesh agent. The next thing we’re going to change is the Step Height. Your nav mesh agent can go up steps and because our floor is uneven, it’s made up of floorboards that are sticking up a bit like that, we need the nav mesh agents to not go like ‘oh I can’t get over that floorboard, I’d better got around it’ so we need a small step height to make sure that it can get up over those bumps. Then we’re expanding the Advanced area and we’re setting the Width Inaccuracy to just 1%, so drag that Width Inaccuracy down to 1. The Width Inaccuracy affects how carefully the nav mesh is baked. A nav mesh can be baked very quickly if you give it high inaccuracies and it’ll look quite angular and it’ll be quite approximate to your environment but we want it to be a very accurate nav mesh. This is going to take a little while to bake but we’ll end up with a very nice nav mesh afterwards. Once that’s done you are hitting Bake at the bottom of the window. What you’ll see in the scene view once it’s completed that process is that you will see a blue overlay on the entire level. You will get a progress bar at the bottom, it says ‘exporting tiles’ like this. Once it’s done that process you will see an overlay in the scene view as long as you are on the navigation window. And it should look something like this. So what’s happening here is nav agents and pathfinding and all that will work with complex meshes, however it is incredibly inefficient and you’re going to have all sorts of issues if there’s bumps and cracks and things like that basically saying that while you can traverse these unusually sized and shaped meshes it’s really not worth it, right? Generally you want your movement to be smooth and you don’t want it to be that inefficient. When we bake a nav mesh what it’s doing is it’s finding all of the static meshes in our scene, things that are marked as navigationally static and saying ‘these aren’t going to move, these are going to be things that we can walk on’ and it’s going to calculate a very simple flat mesh and say ‘it’s not exact but it’s close enough and no one will ever know’ so it’s much more efficient and it actually makes it much more accurate as far as actually moving around how you would expect things to move around. That’s what we’re doing, we’re on the fly Unity is generating a new mesh which is just a flat plane, possibly with a slow to it, but it’s very simplified and it makes the actual AI process of navigating very simple. Just to make this very clear, these things in our scene are marked as static so if we wanted to move our blocks, at some point we changed the design of the game we would move them and we would rebake the nav mesh to recalcuate that traversable area. Okay, so we need this character to run around and chase the player so we’re going to apply animation to this. What we want to do is select the Animation folder in the project panel. I’m going to click the Create button and I’m going to choose Animator Controller. So select the Animation folder and choose Create – Animator Controller. This one is going to be EnemyAC. AC is short for Animator Controller and then we’re going to assign this to our Zombunny. The Zombunny, if we drag and drop that asset on to it it will assign it for us, but just to be clear what we’re actually doing is assigning this to the controller property of the animator. Either drag and drop to that component or simply drag and drop straight on to that object to automatically assign it for you. So when you select the Zombunny you should have Animator – EnemyAC as the asset. So that is a animator controller, a state machine, so I’m going to double click EnemyAC to open it in the animator window. We should have an empty new state machine to add animations to just like we did with the player. As before with the player the animation for the Zombunny is stored within it’s model so I’m going to expand the model and go to the Characters folder in the project. In the project panel open up Models and select Character and then expand the Zombunny and you will see that and it’s animations. The Zombunny has Move, Idle and Death and they are clips that are on a particular point on the timeline. You can see as I go between these clips they are all in a different part of the timeline as you can see from here. The way that you can do that when you bring in an FPX model that you’ve animated is you can just create new clips and tell it what frame range you animated them on and Unity will import those for you as different clips. Just like the player they appear underneath that in the hierarchy so you have Death, Idle and Move. Just as before I’m going to drag them in. I want the default state to be Moving so I’m going to drag that one in first because that gets made default, default signified by orange. Then I’m going to drag in the other two, Idle and Death even. I’m going to put Death next to the Any state, and I’m going to put Idle and Move together. Again the position of these is kind of irrelevant but I like to have things nice and neat. Once those are in there we’ve positioned them nicely we’re going to create parameters for them. So making sure that Move is the default, so Set As Default with right click if you haven’t already, we’re going to create parameters. We have just two parameters for this one and as before we’re going to click the + icon and we’re going to select the type of parameter that we want. We want a trigger parameter called PlayerDead. These enemy characters are going to walk, they’re going to have their moving animation until the player dies and they are going to go in to their Idle animation. Then we’re going to create another trigger which says that they themselves are dead, which is just called Dead. So two trigger parameters, PlayerDead so that they can go to Idle when you get killed and Dead themselves so that they can animate in to their Death animation. Then of course we need to actually control the logic of the state machine. We want our move to transition to Idle so I’m going to right click Make Transition and again I get the transition handle. I’m going to click on Idle to assign it. I will select the transition by clicking on it. Once that transition is highlighted in blue I should have my list of transitions. So in order to go from Move to Idle the condition is that the player is dead. Then very simply in order to go from the Any state I will make a transition, click on Death, select that transition. The condition for that is that the Dead trigger has occurred. So if I just scrub through you see we go from Moving in to Death. Also notice that you can’t go from Idle back to Move. Because at that point the player is dead. So we have no need to create a transition back. These state machines don’t work by themselves The connection between the state machine and animator and the actual functionality is that the scripting needs to tell those parameters what their value is. We need a script to say that the animator SetTrigger Player Dead will actually happen otherwise the animator does nothing by itself. In the Scripts folder in your project you will see a folder called Enemy. Go to Scripts folder and open the folder Enemy. In that you will see a folder called EnemyMovement. We are going to drag and drop that on to Zombunny in the hierarchy. And then once you’ve assigned it either double click EnemyMovement’s icon or go to the cog icon and go to Edit Script, but basically we’re opening that for editing. and when you open that for editing it should look like this. What you’ll notice here is we have a script that’s been ready written for you. Some of the functionality has been disabled, you’ll notice the double forward slash symbols at the start of some of these lines. That’s commenting, so you can write comments in a script, I.E. just notes to yourself or to coworkers, whatever, but you can also use that to turn functional lines of code in to deactivated lines of code, so that’s what we’ve done here and we’re going to come back to this script at some point and enable some of that functionality. But for now we’re just going to explain how this script functions. This is our EnemyMovement script and at the very beginning we have this Transform player, and the Transform player is going to be what the enemy is going to move towards. You will notice the Transform player is not public. With the camera we had that public transform target so we could click and drag in the editor and the camera knows what it’s following. However our enemies are not going to be in the game when the game starts. Our enemies are actually going to be what’s called instantiated or spawned later so whole hordes of them can appear. As such we can’t just click and drag the player on to them. So what’s going to happen is they’re going to have to find the player on their own, so for now that’s just Transform player, not public. We also have a reference to a nav mesh agent, which is the component we put on the Zombunny previously, this is just our reference to it which we’ve called Nav. Now down in the Awake method here we are finding the player. So we have Player, which is that Transform before, player=GameObject.FindGameObjectWithTag. So if you remember previously when we were setting up the player we gave the player the tag Player. So now that we’ve set the player with the tag Player, we can find that player using this function. So basically what it’s going to do is go through all of the game objects in our scene, it’s going to say ‘hey do you have that tag?’ until it finds the one and it gives it back. And then what we’re going to do is say .Transform, which is going to give us a reference to the transform, basically where the player is. So we’re storing that in our variable named player. Next we have a variable named nav and we’re just setting that equal to GetComponentwhich is basically going to pull a reference to the component we have in the editor. At this point we’re just setting up. Then down in our update function you’ll notice we’re using update, not fixed update. As this is a nav mesh agent it’s not keeping in time with physics so we’re just going to use the regular update and inside there we are going to say nav.SetDestination (player.position); and that’s it. So nav being the nav mesh agent we’re saying ‘hey, that’s where I want to go’. ‘I want to go towards the player’ and that’s it, the nav mesh agent goes ‘cool, I’m going to head towards the player’. And the nice thing about doing it this way is that the enemies aren’t going to bump in to each other, they’re not going to crop in and out of each other, they’re going to move around all the creepy baby arms and Legos and weirdness that we have in the scene there and they’re going to viciously and unerringly attack you with extreme prejudice and violence. The nav mesh agent makes it very easy to do these things. And that’s the whole script. We’ll revisit this script later when we want to do uncomment it, re-add in that functionality that you see is currently greyed out. We could switch back to the Unity editor right now, we don’t need to save anything because we haven’t actually edited it, but I do want to make sure you have applied it to Player. So the Zombunny in the hierarchy should have the enemy movement script attached to it. I’m going to save my scene and I’m going to press Play to test my game, when you press Play it now follows the player. We don’t have any coding for attacking yes or anything like that so it’s not doing to do any harm to you, you can walk around and push him around. That is the end of phase 4. Subtitles by the community

100 thoughts on “Survival Shooter Tutorial – 4 of 10 : Adding Enemy one – Unity Official Tutorials (new)”

  1. Did everything exact, also added player to tag, still have NullReferenceException: Object refernce no set to an instance of an ojbect "EnembyMovement.Update()"

  2. NullReferenceException: Object reference not set to an instance of an object
    EnemyMovement.Update () (at Assets/Scripts/Enemy/EnemyMovement.cs:25)

  3. NullReferenceException: Object reference not set to an instance of an object
    EnemyMovement.Awake () (at Assets/Scripts/Enemy/EnemyMovement.cs:14)

  4. If anyone else experiences that the zombear just navigates to 0.0.0 even though you move around and you are 100% sure the script code is correct the solution may be to just restart Unity.

    I found out that the FindGameObjectsWithTag("Player") actually returned 4 instances even though the game object with that tag is only added once.
    The three first instances was named "Player(Clone)" and the last one was the actual player object with tag "Player".

    Anyway after restart the method returned only one instance which is the correct one.

  5. Hi ! Having an error, "Failed to create agent because there is no valid NavMesh". I've created the Nav Mesh Agent on the Zombunny, also it unallows me to click "Bake"@13:00.

  6. I had a problem where my Zombunny would not move from its place, it would always face towards the player, and it would always show the walking animation but it would not move.

    My solution was that in Bake i set my Step Height to : 0.2 
    Then i baked, any my zombunny worked perfectly.

  7. My enemy didn't move because I added all the components to HitParticles, within Zombunny, rather than to the actual Zombunny parent.
    You can copy all the components one by one from HitParticles (using the toggle icon) onto Zombunny, then delete them from HitParticles.
    I rebaked and it worked, the enemy followed my player around fine.

  8. "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    EnemyMovement:Update() (at Assets/Scripts/Enemy/EnemyMovement.cs:25)
    any suggestions?

  9. I need help please, the enemy don't move, the error is "Object reference not set to an instance of an object"

  10. Umm I need help.. mine says:

     NullReferenceException: Object reference not set to an instance of an object
    EnemyMovement.Awake () (at Assets/Scripts/Enemy/EnemyMovement.cs:15)

    also another problem is that mine Zombunny just stays at the same spot! Please help! I tried everything!!

    what do i do help!!

  11. I don't have width Inaccuracy % and height Inaccuracy %… I only have Manual Voxel size… Using Unity 5.0.0f4

    Ha who knows why my Zombunny floats in the air when it follows me 🙂

  12. Great video (good use of zoom in during the presentation, making it easy to follow with Unity and the video side by side on the same screen)

  13. Navigation in version 5 is different but messed around with it. Love the bunny chasing my Player around 🙂 Great tutorial so far 🙂

  14. Whoever got the error "Object reference not set to an instance of an object" could try to comment "if(…)" and "else" in Update() since we don't have any enemyHealth or playerHealth right now.

  15. Using Unity 5.0: There's no Width/Height Inaccuracy option, instead there is "Manual Voxel Size".

    Someone suggested using a Voxel Size value between 0.1 and 0.05 to make it look like the Nav Mesh in the video. I tried this, but it created strnage artifacts:
    With a value closer to 0.05, the cracks in the floor (floor board edges) that were supposed to be just for visual effect counted as untraversable, so the Nav Mesh went around some of them.
    Using a value closer to 0.1, there were triangle-shaped holes in seemingly random places in the Nav Mesh.

    I played around with it for a bit and by accident found that a much higher value for the Voxel Size actually produced a better Nav Mesh.
    I ended up with a Voxel Size value of 0.5 (1.50 voxels per agent radius) as a perfect value: No artifacts, while still keeping inaccuracies at a minimum.

  16. The EnemyMovement script needs a small update for unity 5

    player = GameObject.FindWithTag ("Player").transform;

    is the correct syntax for that line

    GameObject.FindGameObjectsWithTag is no longer a function of the GameObjets Method

  17. Help?
     "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    EnemyMovement:Update() (at Assets/Scripts/Enemy/EnemyMovement.cs:25)

  18. If you are havin the error "NullReferenceException: Object reference not set to an instance of an object" thats probably because you just copied the code from the site and didn't put the "//" in front of some code lines like on the video. You just need to put "//" in the same code lines of the video, it worked with me.
    Sorry for my bad english.

  19. Help plss…. NullReferenceException: Object reference not set to an instance of an object
    EnemyMovement.Update () (at Assets/Scripts/Enemy/EnemyMovement.cs:25)


  20. Help, got:

     "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    EnemyMovement:Update() (at Assets/Scripts/Enemy/EnemyMovement.cs:25)

    Bake button completes in a split second, but it doesn't show any nav meshes

  21. My rigidbody component doesn't have the 'constraints' checkboxes. Was this removed for unity 5?

  22. can someone help?
    when I bake there a massive gaps near and around objects and walls which I know the enemies will not be able to cross

  23. need some help here guyz why my enemy doesn't face me, while following me. is like his face has only one direction … another help here, I can move my character everywhere but the camera don't follow in my character. why is that? please I need help anyone?

  24. @Unity Ok i just copied the script from the website and the bunny doesnt move :/ he just stands there with the walking animation

  25. I did exactly the same but when the enemy follows. The animation plays just once and stops. Then it starts following the player without animation. Just sliding. Help please. I have been stuck from last 2 days.

  26. Having a weird issue where running against a wall bugs out the bunny chasing me, starts walking in a seemingly random direction, facing the player but sliding the wrong way as it moves, being really jittery as it does a times.

    It obviously knows where I am because it faces me, but the movement does not at all match, wondering if there's some weird navigation bug with something moving against a collider.

  27. (Unity version 5.3.0f4)

    Script: EnemyMovement.cs

    For everyone who has this issue: "The enemy go towards the 0,0,0 point, then stops and do anything else.

    That's because there's an issue with the FindGameObjectWithTag function. Try using GameObject.Find instead. I don't know what this is happening. But i know how to resolve it. Use GameObject.Find instead FindGameObjectWithTag if you make Debug.Log(player.position) and you get always 0,0,0 no matter what position the player really is. You are welcome.

  28. is this script transferable? I mean if i use this course to make a game with my own characters and environment, will it still work? To further iterate my question, does this script pertain only to the file that the creators in the video are importing assets, particles etc from?

  29. i'm getting the error NullReferenceException: Object reference not set to an instance of an object
    CompleteProject.EnemyAttack.Update () (at Assets/_CompletedAssets/Scripts/Enemy/EnemyAttack.cs:65)

  30. I'm using Unity 5 and have been able to follow along so well until this point. I used the EnemyMovement script and the Zombunny won't move. I've tried restarting Unity and changing some code, but nothing seems to be working. Anyone know how to fix or having the same problem?

  31. When I set step height here 12:06 to 0.1 , appears a message under this field that says: "Step height conflict with Max Slope. This makes some slopes unwalkable. Consider decreasing Max Slope to < 14.0 degrees. Or , increase Step Height to > 0.38"

    And, in advanced I don't have the Width and Height Inaccuracy adjustments. What I have is "manual voxel size".

  32. Hey I am a sound engineer, motion gfx, learning unity3d, looking to work on some games and learning projects, hit me up

  33. I have strange problem.
    I set the position of enemy to 0,0,0( or any other) but when I click "Play" the enemy teleports to the top of the chair in (6.36, 5.71, -13.20) position. When I click "pause" and i move enemy from there and "unpause" the enemy again teleport there. He try to follow me but he is on chair. Where is the problem ?
    Something wrong with Nav Mesh Agent. When I turn it off, the enemy dont teleport there

  34. I did everything but when i press play the bunny will go up on the chair and walk there…. meanwhile my character is still on the floor, any solution pls?

  35. I'm using Unity 5.3.4…

    I was having an issue with my ZomBunny standing on top of the stool with limited movement. I went to the forums and learned that the 'Floor' (Base, Planks and Sides) area has to be set to 'Walkable'. Here is what I did:

    In Hierachy, go to EnvironmentFloor….

    You may only see three areas highlighted in blue (stool, dresser, and dollhouse).

    Next, make sure that 'Floor' is selected and click on the 'Object' table in the Inspector. Under Scene Filter, choose 'Mesh Renderers'. Click on 'Base' and put a chekc in the 'Navigation Static' box. Make sure that 'Navigation Area' is 'Walkable'. Do the same thing for 'Planks' and 'Sides'.

    Once you're done, click on the 'Bake' tab. I set my 'Step Height' to 0.34. and 'Voxel Size' to 0.2. Click on 'Clear' and then 'Bake'. The ZomBunny should now work as designed.

    I hope this helps.

    Look for the post under 'Umbra1' (#298):

  36. For those having issues baking the navigator mesh in the newest version of unity,

    the "floor" child of "environment" in your hierarchy is NOT static. go check that box 🙂
    then increase step height (the documentation recommends 0.34)
    then in advanced change voxel size (documentation recommends .025 but i think they meant 0.25 cause otherwise the cracks wont get covered properly)

    flying away

  37. Hi.  This all works fine but I cannot see what is telling unity to face the Zombunny to the player.  How does it know the front of the Zombunny as it appears to always be 'looking' at my player as it approaches via the NavMeshAgent?Thanks in advance if you can help.

  38. my zombunny doesn´t follow the player, it just stay in the same position running the animation….Help!

  39. The version I downloaded doesn't have width and height inaccuracies under Bake advanced tab so what should I do ?

  40. So my player is walking through walls and off of the map and through the surrounding items plus the zombunnie except the drawer, the bat and the dollhouse. How do I fix this and thank you in advance.

  41. to anyone still having problems with getting the zombunny to follow – I realised that I had the light at origin tagged as player and the player was untagged – obviously a mistake I made at the very start of the project. Swapping this over sorted the problem for me.

  42. On the Navigation for Environment, my "Bake" settings are different than those in the video. I do not have Width Inaccuracy or Height Inaccuracy. I'm using Unity 5.4.03f. Does anyone know what the sub for these is or where they are stored in this version?

  43. I'm following along the tutorials. But there's something I'm pondering about, since I watched a few of the videos in Unity Tutorials before. Were the hosts for this training day John Goldstone, Mike Geig, and James Bouckley?

  44. I'm having an issue where the zombunny has the walking animation, but it doesn't actually move anywhere. Does anyone know how to fix this?

  45. "Assets/_CompletedAssets/Scripts/Enemy/EnemyMovement.cs(4,14): error CS0101: The namespace `global::' already contains a definition for `EnemyMovement'" Does anyone know what that means? I'm getting that error and have no idea how to fix it.

  46. I did Everything in the video. I've watched it over and over, my enemy plays the moving animation but doesnt even move. Whats worse, it doesnt even turn to the player. Anyone have a reason why?

  47. i'm having a problem with the zombunny animation (Move, Idle, and Death).
    the zombunny follows the player fine, it even sink into the ground when it dies, but the avatar itself does not do the animation movements. please some help.

  48. So the floorboards on which the characters walk are uneven, but the characters' rigidbodys have a frozen Y position. How do these things reconcile?

  49. There are errors: Failed to create agent because there is no valid NavMesh. And "SetDestination" can only be called on an active agent that has been placed on a NavMesh.

  50. For those whose character is not following them,use this code in the movement script

    player = GameObject.FindWithTag ("Player").transform;

    then save it and restart unity. If you character just slides without animating, make sure the animation's 'loop time' and 'loop pose' is checked in the project tab. Thank me later

  51. I love the guy with shaved head and the beard he is awesome and looks like a total genius. Also, he explains everything so clearly and everything just clicks. He is great.

  52. I have this error. Assets/_Complete-Game/Scripts/Enemy/EnemyMovement.cs(4,14): error CS0101: The namespace `global::' already contains a definition for `EnemyMovement'. what should I do?

  53. Help!!

    MissingComponentException: There is no 'NavMeshAgent' attached to the "Zombunny" game object, but a script is trying to access it.
    You probably need to add a NavMeshAgent to the game object "Zombunny". Or your script needs to check if the component is attached before using it.
    UnityEngine.AI.NavMeshAgent.SetDestination (Vector3 target) (at C:/buildslave/unity/build/artifacts/generated/common/modules/AI/NavMeshAgentBindings.gen.cs:35)
    EnemyMovement.Update () (at Assets/Survival Shooter/Scripts/Enemy/EnemyMovement.cs:25)

    (but the zombunny works)

  54. Others have suggested baking a Manual Voxel Size of 0.5 and 0.2, but for the sake of removing any major exploits resulting from navmesh coverage (the area between the alarm clock and the dresser, to be specific), I suggest a Voxel Size of 0.095. You'll see areas where the navmesh isn't covering, even though it's open ground, but the enemy CAN navigate through these areas (for the most part).

    With a Voxel Size of 0.095, the area around each obstacle is small enough to where the enemy can still reach the player and can navigate most–if not all–of the environment with little issue.

  55. Should "has exit time" be unchecked in the Transition between "Move" and "Idle" in the Animator window? I know that it starts with a default condition of "Has Exit Time", but once we add the "PlayerDead" condition, should we uncheck "Has Exit Time" or leave it checked?

  56. I'm getting an error ("SetDestination" can only be called on an active agent that has been placed on a NavMesh.) Zombunny is staying in place while playing the walk animation. Any idea how I can fix this?

  57. Sorry for not knowing your name, but guy with the beard and the black T shirt, you did a great job explaining! I'm a newbie and this lesson threw around some new terminology that you made sure to slow down and explain before moving on which really helped.

  58. using UnityEngine;
    using System.Collections;

    public class EnemyMovement : MonoBehaviour
    Transform player; // Reference to the player's position.
    PlayerHealth playerHealth; // Reference to the player's health.
    EnemyHealth enemyHealth; // Reference to this enemy's health.
    NavMeshAgent nav; // Reference to the nav mesh agent.

    void Awake ()
    // Set up the references.
    player = GameObject.FindGameObjectWithTag ("Player").transform;
    playerHealth = player.GetComponent <PlayerHealth> ();
    enemyHealth = GetComponent <EnemyHealth> ();
    nav = GetComponent <NavMeshAgent> ();

    void Update ()
    // If the enemy and the player have health left…
    if(enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 0)
    // … set the destination of the nav mesh agent to the player.
    nav.SetDestination (player.position);
    // Otherwise…
    // … disable the nav mesh agent.
    nav.enabled = false;

  59. Not all the floor has the blue mesh thing. The mouse hole isn't blue either. Any help?
    I'm changing "floor" under "environment" in "hierarchy" I have In Bake Agent Radius = 0.75, Agent Height = 1.2, Max Slope = 45, Step height =0.1, drop height = 0, jump distance = 0, manual voxel size = check, voxel size = 0.214, min region area = 2, height mesh = unchecked.

  60. I'm getting compiler errors with the EnemyMovement script. "The type or namespace 'Transform' and 'UnityEngine' could not be found. Are you missing an assembly reference?"

    Anyone have help? It won't let me test my game.

  61. Nav Mesh Agent it's something! 😮

    Width inaccuracy doesn't exist anymore, I think the new option called voxel is somewhat to the same thing but not sure how it works

  62. when i click on bake it tells me to save the sceen in the assets folder but it doesn't let me save anywere (assets folder to)

  63. I loved how you guys explained the "pre-written" code at the end, a lot of the time i quit a tutorial when they just copy a bit of code and just paste it into something because i have no idea what just happened, or what am i doing.
    With that explanation i understood every single line of code, and i just wanted to say that its really cool you took the time to make it clear :3

  64. public class EnemyMovement : MonoBehaviour


    """ Transform player; // Reference to the player's position.

    PlayerHealth playerHealth; // Reference to the player's health.

    EnemyHealth enemyHealth; // Reference to this enemy's health.

    NavMeshAgent nav; // Reference to the nav mesh agent."""

    who can tell me line 3 to line 6
    i don't know meaning and function, someone please tell me.
    thank you very much

  65. Hey !
    My zombunny works kinda good, but there is something that bothers me:
    Why does it not point to me ? He moves smoothly, his animations launch without any problem, but it doesn't want to face my player, does he impress the zombunny too much ? Did i create a shy zombunny ? Is there something to add to she script ? (i didn't recognize any rotation function in that script)
    For indication, I'm using Unity 2018.2.16f1

  66. Note: If your enemy character only loops its animation once and then just floats after you, check in the Animator view if you accidentally enabled the PlayerDead parameter. I had the checkbox marked, which makes the game assume you're dead after the enemies' first Move animation loop.

  67. Hello, I love the so very cute zombunny, I do hope I can use it in a future game??? Also, I think it's quite alright for someone to say "zed" when referring to "zee" we will all understand 🙂

  68. For those who are facing the issue of the ZomBunny animating on the spot but not following the player, make sure that you comment out the if statement that the nav.SetDestination is in. This is to be line with the tut video at 22.30. Without disabling the if statement, I also received the error of "Object reference not set to an instance of an object". I see that no one has answered this recurring question.

  69. The script for the YouTube is different from the script for the Survival Shooter Tutorial.
    red —> !
    "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    EnemyMovement:Update() (at Assets/Scripts/Enemy/EnemyMovement.cs:25)

Leave a Reply

Your email address will not be published. Required fields are marked *