2D PATHFINDING - Enemy AI in Unity

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

Комментарии • 1,4 тыс.

  • @lynxiberian7828
    @lynxiberian7828 4 года назад +2589

    Dude, you're literally making my final degree work. If i get the title, i'll get a very good contract in a big enterprise. My life will be very stable. I can't thank you enough for this
    Update: I got my title!
    Update 2: I got fired cause Coronavirus too hard for enterprise apparently
    Update 3: Just got a new job :D
    Update 4 because you guys keep asking haha: They had me doing boring simple stuff so I moved to another enterprise where I work on a way more interesting project ^^
    Update 5: Still in the same enterprise but different team and technology. Still not in videogame development but I got a stable life now so no big deal
    Note about the original comment: It wasn't a very good contract. It was decent at best, but young and innocent me didn't know any better lol

  • @Taaaamas
    @Taaaamas 5 лет назад +257

    YES, i've been hoping you'd cover this at some point

  • @kindafunnymonkey
    @kindafunnymonkey Год назад +60

    If you get an error about insecure connections not being allowed it is really easy to fix. Here's how you do it: in the top left click file, then build settings, then player settings, then other settings, scroll down to a setting called allow downloads over HTTP and make sure it is always allowed. it took me hours to figure this out lol

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

      Godsend, thanks for saving me time!! :D

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

      Life saver thanks

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

      The hero we needed

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

      thanks so much i was about to give up ^^

    • @AlfaCatOmega
      @AlfaCatOmega 9 месяцев назад

      You saved me from wasting so many hours, thanks

  • @FriedrichHabetlerMusic
    @FriedrichHabetlerMusic 4 года назад +100

    10:10 Brackeys you have "Flipped the Bird"

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

    Amazing that you released a video a week before I knew I needed it! Thanks my dude. I can always count on your simple, quality explanations for when I'm wandering aimlessly through the sketchy void that consists of 5 year old tutorials that provide complex and faulty solutions.

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

    I like how you show us a way we can obtain this without a lot of work, but also a way we can make this by ourselves

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

    This is awesome! I scrapped a 2D Top Down RPG series because the pathfinding videos were becoming longer than the rest of the series! I didn't realize the free version of that asset was so powerful!

  • @aivancarlostuquero3782
    @aivancarlostuquero3782 4 года назад +120

    Start of the tutorial for hard coders 11:20

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

      thank you

    • @kreyzgr5167
      @kreyzgr5167 4 года назад +29

      @@brangtoggez6363 well that actually wont work, you still need to set up A* and the seeker script which is before 11:20

  • @whiteglint8191
    @whiteglint8191 5 лет назад +224

    In today's Brackeys tutorial: "How to flip the bird"

  • @techtycho4752
    @techtycho4752 3 года назад +19

    Thanks, A* is awesome, I am using it to make my game in the Brackeys 2021.1 game jam!

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

      same

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

      Do you know why the enemies are only chasing the starting position of my player instead of following him around? (the enemies are not placed, they're spawned and both enemies and the player are prefabs

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

      @@sofikirkou idk

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

      @@sofikirkou I'm having the same problem.

  • @jasonredway
    @jasonredway 5 лет назад +324

    Any chance you could extend this tutorial for grounded characters that use the same physics as the player and need to jump to reach platforms?

    • @towercrowgames5115
      @towercrowgames5115 5 лет назад +4

      Yes please.

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

      have you found a solution to having a grounded enemy yet?

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

      Did you ever figure this out ?

    • @ryanvanderlinden5431
      @ryanvanderlinden5431 5 лет назад +57

      I finally managed it after 2 days of knocking my head against a wall. Always brings results.
      in the EnemyAI script where you rb.Addforce(force), (if you want to keep flyers), wrap this in an if statement with a bool (eg. canFly) and if the bool is false, only add force to the x axis.
      I was still having problems with ground units going over slopes. AddForce was just not working for it so I change mine to using rigidbody velocity which fixed it up well.
      Vector2 force = direction * speed * Time.deltaTime; // force that will move the enemy in the desired direction
      Vector2 velocity = rb.velocity;
      if (canFly)
      {
      // If a flyer, apply velocity in all directions
      // rb.AddForce(force); // the old method
      velocity = force;
      rb.velocity = velocity;
      }
      else
      {
      // If not a flyer, only apply velocity to the x axis
      velocity.x = force.x;
      rb.velocity = velocity;
      }

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

      Ryan Van Der Linden how would i make it jump over platforms to reach the player?

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

    As a teacher from QC I realy apreciate your philosophy and the way your videos are builds! Great job.

  • @karficzfrizack2711
    @karficzfrizack2711 3 года назад +8

    Still come back to this vid every now and again. Miss your vids :(

    • @Flare38888
      @Flare38888 3 месяца назад

      HES BACK

    • @karficzfrizack2711
      @karficzfrizack2711 3 месяца назад

      @@Flare38888 Ahah yer, I'm very happy about it! I don't do Godot but if I ever feel like it then I know where to go. :D

    • @Flare38888
      @Flare38888 3 месяца назад

      @@karficzfrizack2711 I was thinking of trying it sometime because it is better optimized.

  • @ChagaThunder
    @ChagaThunder 5 лет назад +15

    amazing content, I can't thank you enough for the effort put into this or the sharing of information. More people should make content like this. Technical expertise and well spoken. There isn't enough i can say about this.
    wonderful job, keep up the great work.

  • @thefunnybuddy4138
    @thefunnybuddy4138 5 лет назад +532

    "Keep Right"
    Turns Right
    Brackey your not allowed to drive anymore.

    • @Cookie204
      @Cookie204 4 года назад +56

      you're* not allowed to write anymore. XD

    • @VidimusWolf
      @VidimusWolf 4 года назад +15

      @@captainfordo1 error 418: I'm a teapot

    • @Aditya-wg3lp
      @Aditya-wg3lp 4 года назад +5

      Alex error 420: me me big boi

    • @BobrLovr
      @BobrLovr 4 года назад +10

      @@Cookie204 "Y"ou're not allowed to write anymore.

    • @iteratedofficial
      @iteratedofficial 4 года назад +9

      @@BobrLovr You're not allowed to ''type" anymore.

  • @10POWERGODDelGODSTEAM
    @10POWERGODDelGODSTEAM 2 года назад +3

    FINALLY, AFTER LIKE 10 TUTORIALS I FOUND ONE THAT WORKED. THANK YOU!

  • @Collcroc123
    @Collcroc123 5 лет назад +11

    I'd love to see you do a video on the whole 3d animation thing, IDK how to tell when its idling, attacking, running, jumping, etc

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

    it's awesome that he made the flying enemy so that you could also use it for top down.

  • @craftgames4120
    @craftgames4120 5 лет назад +7

    Brackeys is the BEST serious you CHANGED my life 😁😁😁

  • @danivalentine1280
    @danivalentine1280 5 лет назад +34

    This is awesome and very helpful, but what about walking enemies that need to jump across platforms or onto higher surfaces to continue chasing the enemy?

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

      That's what I've been wondering for the past 4 and a half hours
      ha

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

      Just program it yourself lol, use a little bit of intuition. For example, I've never done it, but I'd check for ledges one tile or so in front of me and if so, Jump(). If you want to make it sophisticated, check also for ledges that can actually be reached by the jump, so the enemy does not jump fruitlessly into a void.

    • @Shadowsphere1
      @Shadowsphere1 4 года назад +8

      Honestly, from playing and watching tons of 2D platformer games, there aren't actually that many that let enemies jump on platforms to follow players. Obviously, it makes them more viable as enemies, but it's not something I think many games do. Most of the time the enemies just fall under the platforms and the player gets to progress without opposition. In away, from a design standpoint, this works fine since it gives the player a sense of taking care of the enemies without having to brute force them.
      I personally think jumping over grounded obstacles is enough. A platform in the water, just have the enemies stop at the edge or fall into the water and die. Or I guess you could do what Terraria does and give enemies a set jump and if they make it, they make it, otherwise they fall.

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

      @@VidimusWolf Could get complex, but I suppose you could use vertical raycasts to check the corners of the enemy sprite to see if it's on a ledge, and if so, use horizontal raycasts to check a specific distance out that correlates to the limit it can jump. And if it is close enough, immediately jump before it fully goes off the ledge. Anyone using Rigidbodies might not have used raycasting too much, but anyone using raycasting as the basis for their controllers will probably do it that way or similarly (I'm new to raycasting, so I could also be speaking out of my ass)

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

      @@Shadowsphere1 Great response, I like you viewpoint on this!

  • @Chris-jl6vp
    @Chris-jl6vp 4 года назад +16

    What about a tutorial that does navigation for 2D ground-based enemies? I'd love to learn the process behind making entities jump and drop down through platforms to pursue the player.

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

      just don't set gravity to none, and add a box collider to the enemy

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

      Add colliders to the enemy and add a ridgid body 2d so it is affected by gravity.
      As for jumping, your probably are gonna have to do some code on how the enemy will jump when it hits a wall.

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

    these intros are just getting better and better

  • @TheZildjian11
    @TheZildjian11 5 лет назад +15

    If you did a scan and it didn't register any obstacles, it's because you need to add a Tilemap Collider 2D to your tiles!

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

      Top ! Thank you for the information its all I was looking for.

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

      @@TheOneTaboo yall run this bitch! thanks for the info

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

      you sexy gorgeous being xxxxxxxxx

    • @ryanw5500
      @ryanw5500 4 месяца назад

      I did that and it's not working. What else do I need to do?

  • @AndrzejGieraltCreative
    @AndrzejGieraltCreative 4 года назад +13

    What if you want the enemy to use gravity and jump after the player? I'm trying to allow it to use gravity based on the enemy's rigidbody but, it's falling slowly for some reason. When I disable the pathfinding script, it falls normally. When I use the pathfinding gravity, it falls through platforms even though I set the layermask in the pathfinding script to include the platform layer.

    • @praised_goodness
      @praised_goodness 11 месяцев назад +2

      you should try to make the enemy follow after the path only on the x axis and only jump if the next waypoint is higher than a certain threshold and the enemy is grounded

  • @pr0appleman415
    @pr0appleman415 5 лет назад +11

    When i finished my bird enemy at my second enemy which i want to be on ground so i just added some gravity scale on the enemys rigid body and that actually worked.
    Except i want the enemy to jump whenever it needs to.

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

    rip brackeys your tutorials still rock tho

  • @LukeHwarang
    @LukeHwarang 4 года назад +9

    22:06 "That should look even better"
    *bird starts flipping super fast for no reason at all, buggy as heck*
    "Yup, I definitely like that quite a bit"

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

      Yeah, I'm having issues with this as well. Have you found a solution?

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

    1:40 is about where it starts

  • @walterwhite42068
    @walterwhite42068 5 лет назад +25

    Nice man. Just started my phone and u uploaded this vid.

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

    Something worth noting, on path complete you want ot set your next waypoint to 1 not 0. This is especially important if you're updating animations based on speed and direction, and if you're not using forces to control your movement.
    i.e.
    private void OnPathComplete(Path p)
    {
    if (!p.error)
    {
    _path = p;
    _currentWaypoint = 1;
    }
    }

  • @JoeAC5000
    @JoeAC5000 4 года назад +18

    Is there a way to make the enemy only follow the player when their close enough to them? My enemy''s stay in their grid, but follow the player no matter where he is on the map.

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

      I've never used this pathfinding package, but generally speaking I would use raycasting to know if the player is in range with the enemy. Check the package documentation, maybe there is something already implemented there that fit your needs: arongranberg.com/astar/docs/

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

      Just use collider trigger.

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

      Im new to unity haha so i dont know much buy i use collider trigger to turn tell my enemy to follow my player within a distance.

    • @danielesusino7692
      @danielesusino7692 4 года назад +8

      If you're still seeking the answer, this is my script: pastebin.com/7qjvCpwf
      It's a bit different from the one shown in the video :)

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

      @@danielesusino7692 THANK YOU SO MUCH for putting the code in a paste. Way easier to follow and get what you need when it's colored and indented adequately.

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

    Thanks for promoting my skill share course :)

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

      www.skillshare.com/classes/Unity-Basics-A-Monetised-AndroidiOS-Game-in-4-Hours./1482234656

  • @elpainto1
    @elpainto1 5 лет назад +4

    AddForce already scales by fixed delta time ^^. In fact, if you do AddForce(direction.normalized * mass * drag * speed), you'll get a max velocity that is equal to the speed measured in units per second. Great video!!

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

      I took away deltaTime and now the sprite is zooming all over the screen.
      Pretty sure you need deltaTime in there.

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

      @@saydoer That's because FixedDeltaTime still returns 0.02 (by default) so if you you multiply by it, it'll change your end result. It's basically multiplying by FixedDeltaTime once automatically in addForce, and again when you do * Time.FixedDeltaTime. My guess is that you might be using large numbers like 500 for addForce which is a lot. Also if by chance you are doing addForce in Update instead of FixedUpdate then you might be adding that force more often than needed. Try the formula I mentioned above in Fixed Update with those values pulled from the rigidbody and you should get really consistent, predictable results. The catch is you'd have to either not use zero for mass and drag, or you'd have to add some small number in the code to keep it from applying a total force of zero

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

      @@elpainto1 I'm following the video in all respects, so yes these are going into FixedUpdate.
      I am adding a force of 500 for the speed, so that is probably what's causing it.
      Even after reading your description, I don't understand the difference (aside from the math) between your way of forming this vs. using force = direction * speed * Time.deltaTime.
      What, exactly, is gained by doing it your way?

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

      @@saydoer what you get when you bring in those other values is that the resulting speed is ( or is close to) a velocity in units per second that matches the speed variable you pass in, even if you change the mass and drag of the rigid body in the inspector.

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

      Maybe it's 3 yeas after, but I need to say your answer saved my project! Thanks!

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

    This tutorial worked like a charm for me this time. Came back to it when i got a better understanding what the codes meant.

  • @stepheninczech
    @stepheninczech 5 лет назад +10

    Having some issues with this. I am using this code, but having my object move a set distance each update in the direction of the "direction" vector created using this code (as opposed to applying a force like the video does). But when the path invokes again and recalculates a new path to the target, there is a weird stutter that occurs. I think it is that the first new node that is generated when the path recalculates is actually slightly behind the object, causing it to turn back for a second, then continue moving towards the target. It creates a very disjointed-looking result. I haven't been able to solve this. Anyone have any ideas?
    Edit - Fixed it by making it so that when the currentWaypoint = 0, the vector current_waypoint is calculated using currentWaypoint +1 instead of currentWaypoint. Thereby skipping over to the next way point after a new path is calculated.

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

    Yer videos are incredibly simple to follow and understand. Makes it super easy to Learn and actually Retain information. Thank you!

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

    Brackey: *makes reached end of path variable*
    Also bracket: *never reads it again*

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

    I ALREADY MISS U GUYS, IVE SEEN THAT INTRO LIKE 3 TIMES AND IT ALWAYS MAKE ME LAUGH

  • @saltyscrimp
    @saltyscrimp 5 лет назад +8

    10:43 when I execute the flip script the a* pathfinding script sets my sprite scale to 1 even though I want it at 7, any way I could change this or prevent it from happening?

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

      try to make thу flip transform.localScale = new Vector3(-7f, 1f, 7f);

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

      @@mikhailperkhov figured it out thànk you

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

      I know you said you solved the problem, but you could also go to the 'Import Settings' for your sprite and adjust your 'Pixels Per Unit' value until a scale of 1 looks like your current scale of 7. Then you won't have to write the extra code.

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

      @@soco5338 stopped working on that project but thanks anyway:-)

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

      @@omada10dipae rather than using the editor to change the value, I used my main player script and manually updated the scale on each tick.

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

    Thank you so much for this! I hope you'll keep going with this platformer pathfinding stuff and expand it further. There seems to be tutorials and assets for everything other than platformer pathfinding.

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

    At 18:30 you also need to change Time.deltaTime to Time.fixedDeltaTime
    You could also set rb.velocity instead of Force and when Enemy reach destination set rb.velocity = Vector2.zero So, you won't have any overshooting.

  • @FC-BS
    @FC-BS Год назад +1

    Thanks for this video, it helped me with my task at school

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

    thank you for the Video! but why i can't find tha component named : pathFinding ???!!!! PLEASE HELP

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

    I had a problem with a similar code where I couldn't figure out how to implement a function and this video helped. Cheers

  • @09SkyFrost
    @09SkyFrost 3 года назад +6

    Me sees description saying Line of code
    :D
    also me seeing its his merch store
    D:

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

    I've been waiting for you to do this video for a while. Great stuff👍👍

  • @peterhernandez5377
    @peterhernandez5377 5 лет назад +4

    How should we modify it for special enemies though? Like - what if an enemy needed to move in line of sight to fire a projectile? What if they had to manuever through an environment by jumping around or climbing ladders?

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

    I already knew how to do this but I watched the video anyways cause I always learn something new from your videos, no matter what.
    I wasn't wrong :D Thanks, Brackeys!!

  • @philippe6918
    @philippe6918 5 лет назад +40

    HAHA intro XD, I thought there was a glitch with my computer lol

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

    I think the biggest thing I learned from this was InvokeRepeat, never knew that was a thing, oh boy will things become easier from now on!

  • @mehdibadaoui1658
    @mehdibadaoui1658 4 года назад +7

    your videos hit different now that i know you won't make anymore

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

    brackeys = god of unity youtube

  • @PLSchannel
    @PLSchannel 5 лет назад +69

    My new dream: Take a photo with Brackeys on my graduation day.

    • @apchioryalexander6839
      @apchioryalexander6839 4 года назад +7

      How to pronounce you last name?

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

      @@apchioryalexander6839 Peeticharoenthum

  • @Mekhel
    @Mekhel 5 лет назад +30

    1:22 imagine saying that out loud in public

  • @ceejaylignes1971
    @ceejaylignes1971 5 лет назад +5

    This is the tutorial I've been waiting for. Thank you brackeys!

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

    I should learn by now that when in doubt, search for Brackeys. 2D pathfinding for a Metroidvania type game has been rattling my brain for a bit. 2D sidescroller pathfinding in general rattles my brain. Thanks for supporting the Unity community!

  • @Robertganca
    @Robertganca 5 лет назад +109

    Brackeys: “Alright, let’s make some enemies.”
    Me: 😂😂😂

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

      that was enimeis you deaf!!

    • @avo143
      @avo143 5 лет назад +5

      @Levi Ackerman I don’t know if the way you spelled “enemies” was spelled wrong on purpose or not...

    • @tobi311
      @tobi311 Месяц назад

      those who know: 💀

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

    Me in my dungeon having a nice time coding and seeing Brackeys' black bg not hurting my eyes.
    0:49: ono, your skills hare wants to burn your eyes out lol

  • @tic-tac-tocgames7310
    @tic-tac-tocgames7310 5 лет назад +19

    How about a tutorial for dummies on how to use the unity 2019 new physics features to predict trajectories?

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

    That joke at the beginning ! Love it !

  • @muntasirchowdhrymridul64
    @muntasirchowdhrymridul64 4 года назад +8

    I followed this tutorial and created an enemy in a top down game that follows the player.... I then created an enemy spawner script in the main camera and turned the enemy object into a prefab... But when I put the prefab into the gameobject in the inspector the spawn is working but the enemy does not move... I put the prefab on the screen and the same problem occurred.... In short I am unable to move my enemy when I use it as a prefab.... What's with this issue? anyone has a solution to this?

    • @cceerroonn
      @cceerroonn 4 года назад +8

      You need the script to automatically find the player to chase. You can add a line in the AIDestinationSetter script:
      void OnEnable () {
      target = GameObject.Find("Player").transform;

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

      @@cceerroonn thats perfect

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

    I already miss these guys

  • @urgian
    @urgian 5 лет назад +7

    It would be interesting to see the AI of the ground character. With his reaction to obstacles and abysses.

    • @DarkGrisnak
      @DarkGrisnak 5 лет назад +4

      Well, with the A*, he will just go under the target and try to fly 😅
      But it would be very interesting to look at how to make an AI able to jump over holes and (why not) go back to gain momentum and jump further !
      But I don't think we're going to see this on Brackeys because it's more about algorithm complexity than use of unity and its assets, unfortunately.

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

    FOR THOSE WHO ARE GETTING GENERAL ERROS, just download different packages from the webpage he showed, doesnt need to be exactly the one he downloaded, one of those might work. The one he downloaded didnt work for me, then I downloaded 5 different ones (from the same link in the discription, just different versions), some of them worked partially, until I found one that worked completely.

  • @ho-jeonglee5860
    @ho-jeonglee5860 5 лет назад +7

    Thanks for another great tutorial!
    A great start for a beginner.
    However, could you go over 2D grounded pathfinding with jumps and gaps, too?

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

      I'm finding that way too!

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

    I will never wonder why this channels wasn't remembered as a how to install plugin channel instead of an actual coding channel

  • @gencidurollari7841
    @gencidurollari7841 5 лет назад +7

    Please make A SIMPLE Racing game that we can make in like 15 minutes. Love your videos. You are my favourite. Keep up the good work mate. Thumbs up from me.

  • @robertpiwowarek5354
    @robertpiwowarek5354 5 лет назад +5

    Hey @Brackeys I have encountered a problem where the Scan button doesn't create unwalkable spaces around my obstacles (despite them having a similar settings to yours, did you ever happen to have similar problems? Do you have any suggestions? (tried potentially checking Z on my obstacles related to A* and setting them at the same level, as different ones didn't work, tried thicc height testing, my objects do have box colliders) And I sort of run out of ideas here as to what could be wrong.

  • @BloodHoundPL
    @BloodHoundPL 4 года назад +7

    Hey, a really cool video you got there.
    Do you really need to use external A* when you can just lie your game down onto XZ plane and bake the NavMesh on a plane under the tilemap?

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

    Awesome, please create more videos on 2D 👌🏻

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

    4:33 Even when I set my Obstacle Layer Mask to a certain mask, the graph shows that everything is selected.

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

      Are you sure that your obstacle object has a collider?

  • @Hamstermoviespro
    @Hamstermoviespro 5 лет назад +10

    Hey there Brackeys, Great video, I was definitely looking for something like this! I have a question however, when you write the code to flip the Sprite based on the direction it wants to travel, is there any reason why you use the local scale to flip the Sprite over the the SpriteRenderer.flipX property? Thanks.

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

    This is great, but would love if you could make a video showing more of you making the A* code! Its really easy to learn from you!

  • @codegame7914
    @codegame7914 5 лет назад +17

    Can you make a tutorial on in-app-purchases? There are no good tutorials out there and it would be amazing if you can make one

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

      Wont they be illegal soon tho? No more lootboxes

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

      No, it will not be illegal, actually. Lootboxes just have to require the odds of getting items in the open, and they didn't say it was for lootbox purposes.

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

    Im folowing your tutorial series in wicht you teach how to make a platformer in 2d... I had problems with the pathfinding beacause it was old.... But here you are with a new video of this.... I love you!

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

    I wish you would have explained "nextWaypointDistance" a bit, since it can yield very different results based on the game you're making. I've found that increasing that value doesn't move my own character to the expected location. Decreasing it however makes you end up closer to the clicked location.

  • @OliveriousYT
    @OliveriousYT 8 месяцев назад

    Thank you so much, this will help with customer pathing in a top-down shop managing game! Hope you're enjoying life post-RUclips :)

  • @drax_bs4974
    @drax_bs4974 5 лет назад +11

    you should make a livestream focused on beginners, teaching them the basics of scripting in unity and etc!

    • @las9674
      @las9674 5 лет назад +13

      Or you could watch his series “How to make a game in unity”

  • @Innervision-w6p
    @Innervision-w6p 3 года назад +1

    He was a legend😢😢

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

    This came at such a right time. Could you please do some more on AI and some on testing??? That would be really helpful and thanks man, your videos are such an immense help...

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

    You’re doing the lords work. Keep it up!

  • @DarkGrisnak
    @DarkGrisnak 5 лет назад +5

    Super helpful, thanks ! ;)
    However I think there is a little mistake here. Your condition to increment currentWaypoint makes the AI not going to the end of the path. the "newtWaypointDistance" acts like the endReachedDistance. Be careful for those who'd like to use it, that could surprise you :)
    (It was a problem for me as I needed precise movements)

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

      how did you fixed that? I'm trying for 2 hours, please help me lol

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

      @@bwulf any fixes??

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

    Summertime; Time to binge all you videos

  • @hypnoticturtle9384
    @hypnoticturtle9384 4 года назад +13

    Is there anyway this could work for a randomly generated level?

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

      Not with the free version, i don't think so. the A* pathfinding project has a paid version on the asset store for 100$ that allows for that kind of thing as far as i'm aware

    • @sefiron91
      @sefiron91 4 года назад +15

      Run : AstarPath.active.Scan(); once your level generation is complete or when it gets updated, that should rescan all your graphs.
      I don't know if this is the best way but it's doing the job for now ^^

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

      you just need the generated prefabs to be on a "obstacle" layer. idk about the size of the pathfinding area but depending of what you want to do you can make a level that moves instead of the player (like those running mobile games)

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

      @@sefiron91 That's personnaly what I've done and it works good enough for my randomly generated levels

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

      If you are procedurally generating a big (or infinite) world, you could attach the Procedural Grid Mover (comes with A*) in the same object that has the Pathfinder, attaching the Player (or the Camera) as the target on the script. This is WAY more cheap than scanning every time.

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

    Glad I watched the second half of this with the custom script. I spent hours trying to find a solution to why using all the default methods caused enemies to just overlap eachother and ignore colliders in general. Now my enemies crash in to each other the way I want it to.

  • @Zarakikov
    @Zarakikov 5 лет назад +17

    How could one translate that to fit an enemy that doesn't fly but has to jump around the level just like the player does?

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

      Put objs that make enemy jump in different positions with:
      OnTriggerEnter(){
      Jump();
      }

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

      cast a ray, and after the ray hits a wall it jumps.

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

      I'd say it's mostly the same, only add the force in the X axis and have your enemy continuously jump up when either the path goes upward, or if the player Y is higher than its own. If you want it to only jump when there's a wall in front, a simple raycast forward should be sufficient to check :)

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

      Maybe compare the x and y coordinates like if the if the enemies x is greater than the players x make it go left

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

    Thanks Brackeys! I love the A* algorhtym and watch any video I see on it. I think I'll try this system since I don't have anything designated for 2D A* yet.

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

    You should have seen the smile on my face when he said: no coding!

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

      If you don't like coding, you should probably switch to something like unreal engine lmao

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

      @@sneggulf Well I do like coding, and I prefer Unity for the community, but I just don’t like writing loads of C# scripts

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

    this is exceptionally helpful, thank you!

  • @N4m43
    @N4m43 5 лет назад +16

    Wait.... In the end you didn't use your "reachedEndOfPath" boolean didn't you?
    Because if it ends up true you just return from your FixedUpdate, and if it's false it's not used anywhere.
    Well, it could be useful if you want to add some other functionalities within this script anyway.

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

      Also it is never true.

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

    Awesome video as usual! I was expecting this topic some time ago. Thank you very much! :D

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

    For some reason, when I implemented the A*, it stopped my character from jumping. I am using the same script that he used in the 2d movement tutorial. Any help?

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

      In the Character Controller 2D (Script) of the player, add the Obstacle layer to "What is ground"

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

      @@juancruzgarciamayocchi4509 Thank you!

  • @prithvi.g_
    @prithvi.g_ 4 года назад +1

    7:15 look at the bird
    There was an attempt to keep things PG
    And there was a failure

  • @turtlex5015
    @turtlex5015 5 лет назад +5

    Do i need that a* thing for the second part of the video because I can't find Ai path and *using pathfinding* doesn't work.

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

    THANK YOU SO MUCH! Tomorrow is my final project and my enemy did not move no matter what I did, thank you, not only now it moves, it also was easier to do!

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

    great tutorial but when I tried to flip the bird in the script it told me that "the type or namespace 'AIPath' could not be found (are you missing a using directive or an assembly reference)" but the thing is I did use the using Pathfinding tag

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

      same issue please help :(

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

      @@aaarslanbek Never figured it out

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

      I'm pretty sure that this is just an editor problem. I have the same thing and Unity doesn't complain but only Visual Code.
      Edit: and the code work as it's supposed too, it's just that Visual Studio is complaining for no reason

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

    Great video!
    I was looking forward for this video for days..
    Thanks Brackeys!!!

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

    AIPath doesn't work n my game. I used the same version as brackeys dis but the using directive doesn't have a AIPath Object for me. HAve somebody an idea how to slove this?

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

    You are the bestttttt game dev youtuber 😍. You always brings with new and unique tutorial. I like the way you explain things.

  • @violincrafter
    @violincrafter 4 года назад +8

    7:13 Oh god what are the characters doing