ENEMY AI - Making an RPG in Unity (E10)

Поделиться
HTML-код
  • Опубликовано: 4 янв 2025

Комментарии • 840

  • @LeonardoSilvaHavelock
    @LeonardoSilvaHavelock 7 лет назад +633

    Dude, what you do on youtube.. teaches people for free is just too much...,I'm very grateful to you, all my skills with unity and even learning English I'm getting into these classes, thank you.

    • @James-zr1lu
      @James-zr1lu 6 лет назад +21

      Technically it isn't free. The video is monetized by ads. So, it costs you your time.

    • @AMBafoon
      @AMBafoon 6 лет назад +13

      James which is more valuable than money if you think about it

    • @gorgestboi1028
      @gorgestboi1028 5 лет назад +6

      @Big Smoke PINEAPPLE ON PIZZA IS AMAZING

    • @mainaody3997
      @mainaody3997 5 лет назад +3

      @@andrewnagengast2349 the pineapples on pizza part got me lol

    • @pitanga1724
      @pitanga1724 4 года назад +3

      Mds, achei um BR! Aleluia!!!

  • @yasg5922
    @yasg5922 4 года назад +451

    If anyone has a set destination error, follow these steps
    1. Select your ground and check static on the top right corner of the inspector.
    2. Keep your ground selected, and go to the Navigation tab. (Window>AI>Navigation) Then you should see a tab in Navigation called bake. Select it, and click bake on the bottom.
    3. Play test your game. It might work it might not. If it doesn't work, follow the next steps. If it does, you are good to go.
    4. Move your enemy ai closer to the ground.
    5. Play test your game again. It might work it might not. If it doesn't work, follow the next steps. If it does, you are good to go.
    6. If your enemy gets stuck in the ground, select your enemy, and in the NavMeshAgent, play around with the base offset. You should see a cylinder. Make that cylinder touch the ground.

  • @Yonac
    @Yonac 5 лет назад +302

    "if we get closer to our enemy, it will start to chase us, *AWESOME* "

    • @__Rizzler__
      @__Rizzler__ 4 года назад +5

      "Hehe boi u have got some knowledge" - words of an old dog

  • @nirangasithara4925
    @nirangasithara4925 3 года назад +3

    After all these years I still come back to your videos..... Awesome Job my man !!! Mad Respect !!!

  • @finanzenkeine
    @finanzenkeine 4 года назад +3

    mate you are simply the best everytime i watch a tutorial elsewhere they jugle theyre scripts between episodes so that you have to watch every of theyre episodes but you do a complete video where you explain everything regarding one topic. i love your videos :) you are the best mate keep up the good work you made my day

  • @ContinualImprovement
    @ContinualImprovement 7 лет назад +88

    Man, I love your videos. Especially these RPG ones 👌

  • @dprazo
    @dprazo 4 месяца назад +1

    6 years later and this video is still doing better than most recent videos

  • @s4mcreed314
    @s4mcreed314 7 лет назад +35

    My days goes awesome when he says "AWESOME!"

  • @rhetorical_
    @rhetorical_ 7 лет назад +12

    Man, thank you for making these tutorials! They're top notch quality and very interesting! Keep it up!

  • @codingTheFuture
    @codingTheFuture 6 лет назад +1

    Love this series. It's been a great help with my current project. Keep the coming!

  • @beastninja5655
    @beastninja5655 3 года назад +2

    7:32 The type or namespace name 'Interactable' could not be found (are you missing a using directive or an assembly reference?), I am getting this error

    • @mosaabmatar4117
      @mosaabmatar4117 3 года назад

      Same here There is no class Named Interactable Its maybe Changed

  • @spook2794
    @spook2794 4 года назад +17

    im getting an error: "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    UnityEngine.AI.NavMeshAgent:SetDestination(Vector3)
    EnemyController:Update() (at Assets/EnemyController.cs:25)

    • @Floyna
      @Floyna 4 года назад +2

      Bake the map again
      (Map > Navigation > Bake > Bake)
      Or put your Enemy more close to the map

    • @cristianbustillo4760
      @cristianbustillo4760 4 года назад

      @@Floyna thx

    • @bobdagamer640
      @bobdagamer640 4 года назад +2

      I’ve hit bake and nothing happened

    • @zzedixx
      @zzedixx 4 года назад

      @@Floyna where is the "map" tab??

    • @Floyna
      @Floyna 4 года назад

      It's the map you use to move you're character
      You can locate it on you're Scene
      Sorry guys i'm late :o
      The method I gave is not universal but maybe it's work for you

  • @averagehumanbeing7932
    @averagehumanbeing7932 3 года назад +38

    when you just want a simple enemy ai and then have to spend a few hours watching his entire series, only for it to break your game

  • @bluedonnut_8096
    @bluedonnut_8096 4 года назад +5

    The type or namespace name 'CharacterCombat' could not be found (are you missing a using directive or an assembly reference?)
    The type or namespace name 'CharacterCombat' could not be found (are you missing a using directive or an assembly reference?)
    please help

  • @_CloudyBunny
    @_CloudyBunny 5 лет назад +18

    Let's start to create deep-learning AI enemy.

    • @thebloocat
      @thebloocat 4 года назад +4

      Yeah! You know any good resources for that?

  • @adarshs5974
    @adarshs5974 6 лет назад +82

    Why is he always Smiling?

  • @arneljansarmiento
    @arneljansarmiento 5 лет назад +1

    just discovered this series now im trying to integrate the parts of these scripts with your tower defense tutorial series to make a 3d kingdom rush type of game, thank a lot for these vids. btw im so new to game development so im really grateful

  • @breewilkinson8787
    @breewilkinson8787 4 года назад +2

    Not to sure why but my target location isnt updated after start. So the enemy will move to the initial player position but not follow the player after the player moves (or if the player is out of the lookRadius). I followed the video, any suggestions?

  • @majesticmaniac6420
    @majesticmaniac6420 4 года назад +6

    if anyone else had the thing that said "SetDestination can only be called on an active agent that is on a NavMesh." I set the ground as static went to window- AI- Navigation then bakedif that helps

  • @valorantworld8895
    @valorantworld8895 3 года назад

    6:45 why slerp, and not lerp? i know that slerp makes spherical path to the target, but i made 2 ai agents, and put lerp in one and slerp in the other, and saw no difference, it worked nice for me, but i just want to know why, ty Brackeys

  • @codemoor
    @codemoor 6 лет назад +19

    The type or namespace name 'Interactable' could not be found (are you missing a using directive or an assembly reference?)
    The type or namespace name 'Interactable' could not be found (are you missing a using directive or an assembly reference?)
    how can i fix it §?

    • @amsyarsyahrizal6423
      @amsyarsyahrizal6423 4 года назад +3

      Sorry I'm a bit late, but to anyone else who has this problem:
      Make sure to watch this video first
      --​ruclips.net/video/9tePzyL6dgc/видео.html

    • @firepuppy7211
      @firepuppy7211 4 года назад +2

      i can help u if u still want it

  • @davidcheung9939
    @davidcheung9939 3 года назад +6

    For some reason Unity shows an error when I try to do Enemy : Interactable...is there a way to fix the interactable error here?

  • @raivologins9299
    @raivologins9299 3 года назад

    I like that u speak fast and dont waste our time 👊👊👊

  • @loucypatucy5974
    @loucypatucy5974 4 года назад +2

    for me when i write OnDrawGizmosSelected it pops up a warning that the (OnDrawGizmosSelected) is declared but never used pls someone help

  • @anhky2010
    @anhky2010 7 лет назад

    Thank you so much, Brackeys! I am looking forward to the next part! :D

  • @tombecker1197
    @tombecker1197 4 года назад +2

    Assets\scripts\Enemy.cs(5,22): error CS0246: The type or namespace name 'Interactable' could not be found (are you missing a using directive or an assembly reference?) what am i doing wrong pls answer this time

  • @BerwinSingh
    @BerwinSingh 4 года назад +6

    I am getting an error "Set Destination" can only be called on an active agent that has been placed on the NavMesh. UnityEngine.AI.NavMesh:SetDestination(Vector3). How to fix this and what is the mistake? Please help me.

    • @Noir-mt3bw
      @Noir-mt3bw 4 года назад +1

      Berwin Singh i have this too.

  • @Sicho84
    @Sicho84 7 лет назад

    I love this series. I don't know how far you want to take it, but topics I would love to see covered are amongst others:
    - changing scene without losing the inventory and stats etc.
    - saving and loading the game (maybe even with savepoints like in some JRPGs like Final Fantasy)
    - trading with NPCs or maybe even have dialogue with different options or even different outcomes
    - a simple system to level up and customizing stats with each level up
    - day/night cycle or weather effects
    I know a lot of these things are probably covered in other videos or you could read up on those topics somewhere online etc. but it would be fun to learn these things in the context of this little RPG series :)
    Of course this list could be endlessly long haha there's so much you could do!
    Anyways, keep up the good work :)

  • @SuperPizdolizac
    @SuperPizdolizac 7 лет назад

    I can't believe how good you are at explaining!

  • @ateKna
    @ateKna 7 лет назад +2

    @Brackeys
    How do I point to my player that I spawned at runtime? I can't use the public method player that you show in the tutorial.

  • @MLDEDXX
    @MLDEDXX 4 года назад +1

    is there another place I can put the player manager beside the game manager since I only need the ai and not the entire

  • @sgyffysgyffy4736
    @sgyffysgyffy4736 7 лет назад +1

    Great work Brackeys!

  • @meltpack8876
    @meltpack8876 7 лет назад +12

    When everyone makes half hour long ai vids but ya boi asbjørn got ai down

  • @BRboi777
    @BRboi777 7 лет назад +1

    Wow what a great channel this is. I've been subbed for sometime and coding interests me. Thanks for the awesome channel! :)

  • @tssper3488
    @tssper3488 4 года назад +4

    I'm stiil wondering how to 'collapse' when using regions in the c# scripts. I looked up keyboard shortcuts but nothing helps.
    Somebody pleasre help...

    • @najeeburrehman3303
      @najeeburrehman3303 4 года назад +1

      there is a - sign in leftside where the region starts click it

    • @tssper3488
      @tssper3488 4 года назад

      Najeeb Ur Rehman Oh ok thanks, helps a lot

    • @VoltFall
      @VoltFall 4 года назад

      @@tssper3488 maybe you should look closer

    • @parkerhall9470
      @parkerhall9470 4 года назад

      it is Control + M + M I think?

    • @Ecoustic
      @Ecoustic 4 года назад

      Lol me too

  • @damienarchaglet8088
    @damienarchaglet8088 5 лет назад +14

    i keep getting this error
    "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    UnityEngine.AI.NavMeshAgent:SetDestination(Vector3)
    EnemyController:Update() (at Assets/EnemyController.cs:25)

    • @DrSTew-qt1mm
      @DrSTew-qt1mm 5 лет назад

      same

    • @kerlonleite1927
      @kerlonleite1927 5 лет назад

      Same.. Any solutions ?

    • @theforgot3n1
      @theforgot3n1 5 лет назад

      Maybe you NavMeshAgent is inactive? Or you forgot to add the component to the cube?

    • @arcadeboy7503
      @arcadeboy7503 5 лет назад +12

      You go to Window>AI>Navigation and once you have the navigation window open, click on the objects that you want to bake a NavMesh and in the bake tab click bake. Hope this helps!

    • @pleckton2972
      @pleckton2972 4 года назад

      @@arcadeboy7503 Thannkksss

  • @EarlyEditz185
    @EarlyEditz185 Год назад

    I couldn't add navmeshagent at the start, it didn't show up from 'navigation > navmeshagent' and searching didn't work

  • @coolgamingmaster2578
    @coolgamingmaster2578 7 лет назад +25

    Can someone help me? I have a problem with the nav mesh agent. I checked my script to be like brackeys' but it don't work. Unity says: SetDestination can only be called on an active agent that has been placed on a NavMesh. UnityEngine.AI.NavMeshAgent:SetDestination(Vector3)

    • @luisguilherme216
      @luisguilherme216 7 лет назад +3

      i have the same problema!! please help !!

    • @coolgamingmaster2578
      @coolgamingmaster2578 7 лет назад +19

      sumerian ozzyz i fixed it. Make a group for the floor and go to window then navigation and its gonna open a bonus window next to the inspector. Then go to objects select mesh renderer and select the floor group(the y axis should be the same) then do this group static - yes for all children and then go back to navigation and bake the floor. Ask if you havent understand

    • @luisguilherme216
      @luisguilherme216 7 лет назад +1

      im trying thanks

    • @luisguilherme216
      @luisguilherme216 7 лет назад +1

      its done but now it appears object reference not set to an instance of na objetc .. : s

    • @coolgamingmaster2578
      @coolgamingmaster2578 7 лет назад +1

      have you dragged it into the inspector (when you create for example public GameObject player you need to drag the object - the player in the inspector)

  • @scottev954
    @scottev954 5 лет назад +1

    Great info on NavMeshes... I was able to get the right information quickly and easily!! Thank you for all of your tutorials.

  • @omnigulwillofcrota8391
    @omnigulwillofcrota8391 6 лет назад +12

    Great tutorial as always! Easy to follow and really helped me out except for the fact that it doesn't work.
    I keep getting this error: Failed to create agent because it is not close enough to the NavMesh.
    Then whenever I get in range i get this error : "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    Anybody know what to do? I already baked the floor and stuff.

    • @Hadidiz
      @Hadidiz 5 лет назад +2

      i had this problem but when i baked the terrain it worked smoothly

    • @freeradical9011
      @freeradical9011 3 года назад +1

      Yes bro I got the same error....

  • @pedrogll6052
    @pedrogll6052 4 года назад +4

    "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    UnityEngine.AI.NavMeshAgent:SetDestination(Vector3)
    EnemyController:Update() (at Assets/EnemyController.cs:27)
    can someone help me?

    • @monkeyballs188
      @monkeyballs188 4 года назад +1

      generate a navmesh for your floor

    • @mateodemicheli2420
      @mateodemicheli2420 4 года назад

      @@monkeyballs188 How i do that? In my Console apears this :
      "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
      UnityEngine.AI.NavMeshAgent:SetDestination(Vector3)
      AgarrameSiPodes:Update() (at Assets/AgarrameSiPodes.cs:38)
      Pleas answer the soon as you can :c

    • @benmohrland
      @benmohrland 4 года назад

      I also got this error. I think I fixed it by placing my character on the ground or at least closer to it.

    • @chosengames4172
      @chosengames4172 4 года назад +1

      @@mateodemicheli2420 Go to the windows tab at the top and find the navigation panel(should be in the AI section). Then click over to the bake tab and bake.

    • @MycoalD
      @MycoalD 4 года назад

      @@chosengames4172 thank you sooooo much

  • @shehzaanansari8204
    @shehzaanansari8204 7 лет назад +2

    This is amazing bro!

  • @ZaCool26
    @ZaCool26 5 лет назад +2

    Can someone help. I keep getting this error: "Failed to create agent because there is no valid NavMesh". I've tried baking it but it still doesn't work! What is wrong???????????

    • @icoderunity5066
      @icoderunity5066 5 лет назад

      hello, to make this work you need to set your ground to static(and your obstacles) then bake turn off Auto lightning if still doesn't and set your obstacles in the scene as "Navmesh Obstacles".

    • @ZaCool26
      @ZaCool26 5 лет назад +1

      icoder Unity Thanks 🙏🏻 it works now 😄

    • @icoderunity5066
      @icoderunity5066 5 лет назад

      No problem, i had that issue too. :)

  • @Glubblub
    @Glubblub 4 года назад +1

    something to note is that if its not working, try going into the PlayerManager script and change (GameObject player) into (Transform player).

  • @opreaandrei4012
    @opreaandrei4012 3 года назад +2

    any ideea why my enemy is coming exactly into me , i mean after he reaches me he stays exactly where i am ( on top of me ) and i cant move . If i put a rigidbody on him , after he reaches me and i attack him or he just touches me he go away and never come back xD . Any help pls ?

    • @dron5734
      @dron5734 3 года назад +1

      did you changed "stopping distance" in navMeshAgent component?

    • @opreaandrei4012
      @opreaandrei4012 3 года назад

      @@dron5734 I tried but not working so well

  • @Nox__
    @Nox__ 4 года назад

    Before brackeys tutorial was a little bit boring like the intro was just "today we are going to make the A.I."
    Bur now we have a mlittle joke in almost every intro
    Brackeys really changed in a good way

  • @patiimusic3701
    @patiimusic3701 4 года назад +2

    I'm very new at this, so I don't know if you've answered this b4 but how do you make the enemy have an angle for line of sight

  • @Psychopsam
    @Psychopsam 2 года назад

    When did the altar object get added? At the start of this video the altar area / ritual area with torches has a platform on it now? Did I miss something?

  • @closed9009
    @closed9009 5 лет назад +2

    error CS0506: 'Enemy.Interact()': cannot override inherited member 'Interactable.Interact()' because it is not marked virtual, abstract, or override

    help!

    • @Corez
      @Corez 5 лет назад

      Have you made a function for it?

  • @oc9438
    @oc9438 6 лет назад

    just a great tutorial overall, even though I cannot donate currently I will be sure to share your channel as much as possible

  • @abdelrhmanmagdey334
    @abdelrhmanmagdey334 6 лет назад +2

    Can you help me , An error appear says ""SetDestination" can only be called on an active agent that has been placed on a NavMesh"

    • @gaddgames
      @gaddgames 4 года назад

      same

    • @mr_moon2374
      @mr_moon2374 4 года назад

      @@gaddgames you go to the windows tab then head to ai then navigation. go to objects then click on your ground then press navigation static. then go back to the bake tab and hit bake. hope that helps

  • @jaridkeen123
    @jaridkeen123 5 лет назад +9

    6:34

  • @ItsCodeRedYT
    @ItsCodeRedYT 5 лет назад

    Thank you so much for this series! I am actually not using this series to make a RPG. Instead, I am using them, to make a MOBA-style game!

  • @Rejnols
    @Rejnols 4 года назад +1

    Hey there! I'm making AI for a school project. I'm not interested in making the whole RPG, just the AI part. Can anyone tell me why i get an error when i change the public class of the enemy to Interact? I assume it because it was created in a previous episode, but i'm not great with Unity yet so i have no clue how to make that.

    • @thelegendarymushroom80
      @thelegendarymushroom80 Год назад

      :( exactly the same problem here. Did you ever manage to find out about it? I also did not watch previous episodes D:

    • @thelegendarymushroom80
      @thelegendarymushroom80 Год назад

      Decided to speed watch all his episodes until I find the reason, then the second episode hit me haha. It's all in Episode 2.

  • @thatrandomguy8567
    @thatrandomguy8567 6 лет назад +8

    I got this error "SetDestination" can only be callrd on an active agent that has been placed onna NavMesh. Any help?

    • @ashothayrapetyan9828
      @ashothayrapetyan9828 5 лет назад

      ​@@juniorasare9769 Thank you

    • @overwhelming9212
      @overwhelming9212 5 лет назад

      @@juniorasare9769 Hey I dont understand this part " open the navigation window, select the floor, go on object and turn on navigation static" could you help me out pls

    • @Aswll
      @Aswll 5 лет назад +3

      @@overwhelming9212 any obstacles or walls you have set it as "Navigation Static" on the inspector (top right corner). In Unity, NavMesh generation is handled from the Navigation window (menu: Window > AI > Navigation). Do the same with the Enemy AI object. I think. Try it and let me know if it worked!

    • @Aswll
      @Aswll 5 лет назад

      @@overwhelming9212 also bake them

    • @Adkinsy85
      @Adkinsy85 5 лет назад

      @@juniorasare9769 thank you ❤️

  • @KEM4OFFICIAL
    @KEM4OFFICIAL 6 лет назад

    Hello.
    Is it somehow possible to handle rotation on raycast hit as you did for FaceTarget() method? Its buggy and not working as same as clicking on object once facing the target (handling rotation without navmesh agent)

  • @Sam-dn9lj
    @Sam-dn9lj 5 лет назад

    I was wondering if anyone could help me on my problem. I have typed in all of the code up to 5:35 and I attempted to run the code and I got this error: "Failed to create agent because there is no valid NavMesh"
    My player has a NavMeshAgent component on it, so I am not sure what I am doing wrong.
    Thanks.

    • @lionn00b
      @lionn00b 5 лет назад

      @@juniorasare9769 Thank you!! this helped

  • @JShunk
    @JShunk 4 года назад +1

    I’m getting the error “MissingComponentException: There is no ‘NavMeshAgent’ attached you the “Enemy” game object, but script is trying to access it.” Any way to fix this?

    • @matthewbrown995
      @matthewbrown995 4 года назад

      add NavMeshAgent to Enemy if you haven't already

    • @JShunk
      @JShunk 4 года назад +1

      Got it thanks!

  • @Joseph-mt3iw
    @Joseph-mt3iw 5 лет назад +1

    I have one problem and it's : NullReferenceException: Object reference not set to an instance of an object
    EnemyController.Update () (at Assets/Scripts/Controllers/EnemyController.cs:22)
    can someone help me please ?

  • @Krexalll
    @Krexalll 7 лет назад

    This is great! I really love your videos!

  • @josephkelly3044
    @josephkelly3044 6 лет назад +3

    I tried to attempt this but form some reason I keep getting two errors:
    NullReferenceException: Object reference not set to an instance of an object
    EnemyController.Start () (at Assets/Scripts/Controllers/EnemyController.cs:15)
    NullReferenceException: Object reference not set to an instance of an object
    EnemyController.Update () (at Assets/Scripts/Controllers/EnemyController.cs:22)
    Anybody have any idea whats wrong?

    • @trallaton
      @trallaton 6 лет назад

      You ever figure out what was wrong?

    • @trallaton
      @trallaton 6 лет назад

      I have it fixed. Apparently the Awake function just wasn't capitalized.

    • @trallaton
      @trallaton 4 года назад

      @Yaq I got you fam

  • @notfunny3684
    @notfunny3684 Год назад

    NullReferenceException: Object reference not set to an instance of an object
    EnemyController.Update ()
    I am getting this error in enemyController

  • @Madmanmpu
    @Madmanmpu 7 лет назад +9

    For some reason, the enemy is not following or moving when the player comes within the distance. Any ideas?

    • @Madmanmpu
      @Madmanmpu 7 лет назад +2

      Apparently my Enemy object keeps sinking into the ground on start... Seems to be preventing it's movement.

    • @Madmanmpu
      @Madmanmpu 7 лет назад +3

      Ok, apparently I had a few errors. My transform for my graphics was offset, and my capsule collider was to tall/wide. Seems to be operating just fine now.

  • @indyt2370
    @indyt2370 6 лет назад +1

    Can someone help me? i have the same coding as Brackeys has for the enemy AI but it doesn't work. Like it doesn't give me any errors at all but the enemy doesn't move

    • @thenumberseven1479
      @thenumberseven1479 3 года назад

      You gotta bake it, see the first comment above. Might be a little late though:)

  • @CypriCar
    @CypriCar 4 года назад +1

    i did a project but when i am going to red gizmos unity give me this error :
    " MissingComponentException: There is no 'NavMeshAgent' attached to the "Enemy" game object, but a script is trying to access it.
    You probably need to add a NavMeshAgent to the game object "Enemy". Or your script needs to check if the component is attached before using it.
    UnityEngine.AI.NavMeshAgent.SetDestination (UnityEngine.Vector3 target) (at C:/buildslave/unity/build/artifacts/generated/bindings_old/common/AI/NavMeshAgentBindings.gen.cs:35)
    Enemy.Update () (at Assets/Codes/Enemy.cs:20)
    "
    Could you help me guys

    • @tdawg6348
      @tdawg6348 4 года назад

      ChlodWin did you try adding a NavMesh?

  • @Zukomazi
    @Zukomazi 5 лет назад +3

    I followed this tutorial to the T, same scripts exactly but the cube would not move. I took off the rigid body, and it works perfect now. Anyone with same problem , try messing with the rigid body

  • @thomasgamerofhazel2296
    @thomasgamerofhazel2296 3 года назад

    u was the best person and u will be on our hurts.

  • @ChristianRuppelt
    @ChristianRuppelt 7 лет назад

    Awesome video as always. Would loooove to see this be converted to a multiplayer / coop.

  • @bex2quik
    @bex2quik 4 года назад +2

    it wont let me derive enemy from interactable pls help!

    • @friesandcats1919
      @friesandcats1919 3 года назад +1

      i have the same problem did you ever fix it? i cant change monobehaviour to Interact able, did you ever find out how to fix it?

  • @Greed-ms2cv
    @Greed-ms2cv 6 лет назад +4

    Thank you for your videos! But i encounter some problem. It is working. but when i put a new enemy not the first one. there's an error "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    UnityEngine.AI.NavMeshAgent:SetDestination(Vector3)
    enemyController:Update() (at Assets/enemyController.cs:35)
    It is the same as the first enemy it have rigidbody, navmesh agent and the scripts that works in the first enemy .
    somebody help me :3

    • @1zc5
      @1zc5 6 лет назад +2

      I have a script that can help you!!! this script
      using UnityEngine;
      using UnityStandardAssets.Characters.FirstPerson;
      using UnityEngine.AI;
      public class AiExample : MonoBehaviour {
      public enum WanderType { Random, Waypoint };
      public float damage = 16f;
      public GameObject fpsc;
      public WanderType wanderType = WanderType.Random;
      public float wanderSpeed = 4f;
      public float chaseSpeed = 7f;
      public float fov = 120f;
      private bool isAware = false;
      private Vector3 wanderPoint;
      public Transform[] waypoints;
      private bool Attacking = false;
      public GameObject radgollZombie;
      public GameObject NPC;
      [SerializeField] private float health = 100f;
      public float viewDistance = 10f;
      private NavMeshAgent agent;
      private Renderer renderer;
      public float wanderRadius = 7f;
      private int wayPointIndex = 0;
      private Animator anim;
      public void Start()
      {
      agent = GetComponent();
      renderer = GetComponent();
      wanderPoint = RandomWanderPoint();
      anim = GetComponentInChildren();
      }
      public void Update()
      {

      if (isAware)
      {
      agent.SetDestination(fpsc.transform.position);
      anim.SetBool("Aware", true);
      agent.speed = chaseSpeed;
      //renderer.material.color = Color.red;
      }
      else
      {
      SearchForPlayer();
      wander();
      anim.SetBool("Aware", false);
      agent.speed = wanderSpeed;
      //renderer.material.color = Color.green;
      }
      }
      private void OnTriggerEnter(Collider other)
      {
      if (hit.GetComponent())
      {
      GetComponent().ApplyDamage(damage);
      }
      Attacking = true;
      anim.SetTrigger("Attack");
      }
      private void OnTriggerExit(Collider other)
      {
      Attacking = false;
      }
      public void SearchForPlayer()
      {
      if (Vector3.Angle(Vector3.forward, transform.InverseTransformPoint(fpsc.transform.position)) < fov / 2f)
      {
      if (Vector3.Distance(fpsc.transform.position, transform.position) < viewDistance)
      {
      RaycastHit hit;
      if (Physics.Linecast(transform.position, fpsc.transform.position, out hit, -1))
      {
      if (hit.transform.CompareTag("Player"))
      {
      OnAware();
      }
      }
      }
      }
      }
      public void OnAware()
      {
      isAware = true;
      }
      public void wander()
      {
      if (wanderType == WanderType.Random)
      {
      if (Vector3.Distance(transform.position, wanderPoint) < 2.5f)
      {
      wanderPoint = RandomWanderPoint();
      }
      else
      {
      agent.SetDestination(wanderPoint);
      }
      }
      else
      {
      if (waypoints.Length >= 2)
      {
      if (Vector3.Distance(waypoints[wayPointIndex].position, transform.position) < 2f)
      {
      if (wayPointIndex == waypoints.Length - 1)
      {
      wayPointIndex = 0;
      }
      else
      {
      wayPointIndex++;
      }
      }
      else
      {
      agent.SetDestination(waypoints[wayPointIndex].position);
      }
      }
      {
      Debug.LogWarning("Please Assign more than 1 waypoint to the me!!" + gameObject.name);
      }
      }
      }
      public Vector3 RandomWanderPoint()
      {
      Vector3 randomPoint = (Random.insideUnitSphere * wanderRadius) + transform.position;
      NavMeshHit navHit;
      NavMesh.SamplePosition(randomPoint, out navHit, wanderRadius, -1);
      return new Vector3(navHit.position.x, transform.position.y, navHit.position.z);
      }
      public void ApplyDamage(float damage)
      {
      health -= damage;
      if (health

    • @finlayf5432
      @finlayf5432 6 лет назад

      @Yaman what should I drag into the NPC ragdoll zombie and Fpsc ?
      And thanks for the script

    • @1zc5
      @1zc5 6 лет назад

      Finlay Fulton drag a prefab that look exactly like the model you are using as a enemy then exclude it from any thing attached to it except the rigid body meaning you need to remove the animator and the Ai script then make it rag doll by right clicking it in the hierchey and press 3D model then press rag doll and assign the bones to it for the fpsc just drag the playable character to it
      Edit: btw when you make it rag doll and making it as a oregano drag it to the zombie rag doll sorry for calling it zombie but because I was using it for my zombie game

    • @dong-kunlee5395
      @dong-kunlee5395 5 лет назад

      Check "navmeshagent.enable = true;:" maybe you have coded disable navmeshagent

  • @amazonindiajunction
    @amazonindiajunction 6 лет назад

    Hi i tried it but it is showing "setdestination can only be called on an active agent that has been placed on a Navmesh"

  • @burpybirb
    @burpybirb 5 лет назад +1

    Who else got a little spooked when he suddenly plays the music

  • @markfourth531
    @markfourth531 7 лет назад +1

    You're really cool! I love your work. keep up :)

  • @ImusingX
    @ImusingX 5 лет назад

    i am using your script and i get the following error:
    Assets/EnemyController.cs(15,2): error CS0246: The type or namespace name `CharacterCombat' could not be found. Are you missing an assembly reference?
    Can someone help me?

  • @alex_HL
    @alex_HL 4 года назад

    I downloaded the zip from github and I tried opening the finished project and it opens but it has a compilation errors. Assets\Environment\PostProcessing\Editor\PropertyDrawers\MinDrawer.cs(6,34): error CS0104: 'MinAttribute' is an ambiguous reference between 'UnityEngine.PostProcessing.MinAttribute' and 'UnityEngine.MinAttribute'. What is this? can anyone help I'm such a noob. I really want to know how to put enemy AI into models!! Please help

  • @Defectoms
    @Defectoms 4 года назад

    Hi Brackeys, great tutorial. Just one question: Is there any reason why did not use a trigger collider to figure out if the player is within your desired radius?

  • @lablabs3726
    @lablabs3726 5 лет назад

    Brackeys you dont have Crafting system video right?
    i was trying to ... but hard to apply to my inventory its kinda confusing

  • @Trevor-cy1kl
    @Trevor-cy1kl 3 года назад

    I have a player object but its a prefab, and the ai wont go to me because theres no way to set target to the prefab

  • @vbwebb
    @vbwebb 7 лет назад +12

    Hey!!
    I'm​ making this game and want switch camera! Do you have any video were you show how to do that? Great videos, keep it up!!

    • @MattRynbrand
      @MattRynbrand 7 лет назад +3

      Just have a reference to both cameras, and simply enable & disable them as needed.

    • @Mr.Adhesive
      @Mr.Adhesive 7 лет назад

      dextrex Victor you could also just store two positions, and always have the camera at one position. This would probably prevent small lag spikes on the other guys method.

    • @leptosurreal460
      @leptosurreal460 7 лет назад +1

      Store 2 empty gameObject and use transform.Translate. You can also use camera.LookAt with the right range.

    • @anandkrishna590
      @anandkrishna590 6 лет назад

      Use Vector3.lerp() instead of transform.Translate().

    • @leptosurreal460
      @leptosurreal460 6 лет назад +1

      Yes! That's a good idea ^^.

  • @tonysopranodrivingsongslover
    @tonysopranodrivingsongslover 6 лет назад +1

    even though I copy everything you do it still doesnt work, "SetDestination" can only be called on an active agent that has been placed on a NavMesh, please someone help me.

    • @alextronic4503
      @alextronic4503 5 лет назад

      you will need to bake nav mesh on the ground they are standing on, its been over an year lol ik, i hope you found it

  • @radradradrad5113
    @radradradrad5113 6 лет назад

    My enemy stops following the player after some time. and also on that line "using UnityEngine.AI;" i'm geting an error so, when i want the script to work i have to disable that line. I'm using Unity 5.0.1f1. is it because my unity version is older?

  • @cheeseydirt84
    @cheeseydirt84 4 года назад

    i follow the instructions and it came up with this.
    "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    UnityEngine.AI.NavMeshAgent:SetDestination(Vector3)
    EnemyAI:Update() (at Assets/EnemyAI.cs:28)
    ?
    what does it mean

  • @liamsykes489
    @liamsykes489 4 года назад +4

    dose this tutorial work for other games and not just the one hes making

    • @braaad2613
      @braaad2613 4 года назад

      im making an fps and i can confirm that it works for my ai enemies most of these tutorials can be implemented into and type of game

    • @liamsykes489
      @liamsykes489 4 года назад

      thank you so much this is really helpfull

  • @iloveabg200
    @iloveabg200 2 года назад

    Hi, i keep getting errors about the enemy scripts saying Interactable. Any fix?
    Thanks

  • @rodrigo.cs.machado
    @rodrigo.cs.machado 5 лет назад +1

    You and Sebastian help a lot. Thanks for the videos and tutorials. I do not know if they stopped creating videos, and if you still have a chance to collaborate on patreon.

    • @francek3892
      @francek3892 2 года назад

      Sebastians AI for the animations kinda suck bcs he didn't showed how he puted the animations to the enemy I tried it several times and it doesn't work. Like the enemy is attacking but am getting errors for the attack animation

  • @rolegames500
    @rolegames500 4 года назад

    Seems when I instantiate the player it doesnt work. If I drag and drop the player into the scene it works fine. This isnt a huge deal but im wondering if there is a way to do it with instantiate?
    and yes I drag and drop the correct prefab into the player spot.

  • @joshuaalvinreturban2554
    @joshuaalvinreturban2554 7 лет назад +2

    I followed your first code but no wiresphere seen. How to fix this?

    • @gagemurphy777
      @gagemurphy777 4 года назад

      Make sure you have gizmos applied in scene window

  • @shadowgodthegamer5738
    @shadowgodthegamer5738 2 года назад +1

    How do i increase the speed of the enemy?

  • @Some-One4
    @Some-One4 2 года назад +1

    how did u collapse it the code ?

  • @ayduntgt4389
    @ayduntgt4389 4 года назад

    Man, I love your videos thank you

  • @favour5442
    @favour5442 5 лет назад

    This is the only video that I've watched that you rushed without explaining much

  • @GameQuestChronicles0909
    @GameQuestChronicles0909 7 лет назад

    Great Work man ...............

  • @hassanislam2894
    @hassanislam2894 5 лет назад

    Sir. NullReferenceException: Object reference not set to an instance of an object
    Pointing this line of code: float Distance = Vector3.Distance(target.position, transform.position);

  • @jackcrane2539
    @jackcrane2539 6 лет назад +1

    Thank you so much,
    Where is the video that makes the enemies fight? I couldnt find it

  • @tallenstudios412
    @tallenstudios412 7 лет назад

    Love these videos, inspirational!

  • @jollysquidlips5610
    @jollysquidlips5610 4 года назад

    so the game I am trying to make, is a sort of zombie wave game, so will all of this stuff still work if I haven't followed any of the other tutorials?

  • @Chaveyo_Viafora
    @Chaveyo_Viafora 3 года назад

    So I am getting an error where nothing is working, the enemy just doesnt move?

  • @LushPop
    @LushPop Год назад +1

    If anyone just so happens to have the issue where their player wont focus on the enemy, remember to remove the boxcollider from the enemy GFX

    • @hamandswizz
      @hamandswizz Год назад +1

      5 years later and the community still coming through

    • @LushPop
      @LushPop Год назад

      @@hamandswizz yup!!

  • @throttlebydc
    @throttlebydc 4 года назад

    i want to create array of players in PlayerManager script...but when i do.....some transform error is showing in enemy script......anybody know why?

  • @ondrejkarbas7287
    @ondrejkarbas7287 7 лет назад +8

    Will you also do saving? That's the only part i don't know how to do

    • @Ownage4lif31
      @Ownage4lif31 7 лет назад

      Ondřej Karbaš usually you store it in xml and load the data. You see that most games have their own file, id be interested too to see how he does it with unity.

    • @ondrejkarbas7287
      @ondrejkarbas7287 7 лет назад

      RandomSilly i know how to do it in simple games (mobile games for example) where you just need to save money, finished levels and stuff like that, but in a gamd where you can save whenever you want it will be much harder

    • @ondraenglish8131
      @ondraenglish8131 7 лет назад

      Ondřej Karbaš make game objects from the XML?

    • @ondrejkarbas7287
      @ondrejkarbas7287 7 лет назад

      Ondra English i didn't know if there was a more optimised way

    • @gastonmolina7784
      @gastonmolina7784 7 лет назад

      You can make a binary .dat file storing your data with a System namespace. Unity has a tutorial for this. Google it, persistance and duration Unity tutorials I guess you will find it that way.