Building a Traffic System in Unity

Поділитися
Вставка
  • Опубліковано 17 січ 2025

КОМЕНТАРІ • 339

  • @elektra81516
    @elektra81516 5 років тому +748

    In under 20 minutes I learned how to make something that would have cost me $50 on the asset store

  • @sharpenednoodles
    @sharpenednoodles 5 років тому +70

    How do you not have a million subs yet? This was amazingly presented, and very easy to follow! Great stuff

    • @MassimoRough
      @MassimoRough 4 роки тому +3

      Have you shared this video so he get a million of subs yet? Why braggin if not?

    • @bmxchamp4
      @bmxchamp4 4 роки тому

      @@MassimoRough I think you may have misunderstood what he was saying. He was saying that he deserves a million subscribers because of how well put together the video was. He didn't mean it in a negative way.

    • @MassimoRough
      @MassimoRough 4 роки тому

      @@bmxchamp4 I think you misunderstood me. I was saying sharing video with others is a way to increase subscribers, while bragging about not having a 1m subscribers does nothing to it.

    • @GLXY_SHADOW
      @GLXY_SHADOW 2 роки тому

      When you realize that your Unity Engine version doesn't like this code and so NOTHING WORKS.

  • @xenibyte5898
    @xenibyte5898 4 роки тому +134

    I'm interested in seeing how you would implement an anti collision system for pedestrians so they don't have glitchy bumpy movement due to colliders. I would imagine using a spherical or circular collider and a script that uses some sort of dampening or weight to slow down and push pedestrians around without being so harsh.

    • @HAWXLEADER
      @HAWXLEADER 4 роки тому +1

      You could give them some sort of force field constraint or even make them physics based.

    • @markiewicz.szymon
      @markiewicz.szymon 4 роки тому +24

      Or you could make it using a Unity build in navmesh to save ton of work. Set sidewalk to walkable, road to not walkable, twak some navmesh agent settings to get more natural movement and you can also easily implement obstacle avoidance. Then you can even make some interesting mechanics that will simulate how people normally move around. Example: go to friend's house > go for shopping > return home.

    • @katebriggs3918
      @katebriggs3918 4 роки тому +2

      I'd do some research into flocking behaviors. That would even give the added benefits of people walking in groups. (But maybe also people randomly switching who they're friends with)

    • @preeteshshirkar5451
      @preeteshshirkar5451 4 роки тому +1

      @@markiewicz.szymon navmesh does'nt help you in creating a lane traffics system

    • @DJLKM1
      @DJLKM1 4 роки тому

      Though it might endup quite system taxing for a large project, but to avoid ped collision, you could add a raycast or preferably a spherecast to the AI script. And detect other objects before a collision occurs. This could also be added to for obsticles on the sidewalk and later for avoiding getting run over :)

  • @liormax
    @liormax 4 роки тому +11

    dude, do you even realize how amazing is the content you are doing?

  • @svedalawoodcrafts
    @svedalawoodcrafts 6 місяців тому +1

    All I can say is WOW! So many cool idea's such as Branching I never thought about before though never worked much with NPC trafficing systems until I now need it in my game. This just blew me away. Looked all day yesterday for good info video's on the subject, found a couple but you my friend made it so incredibly easy to understand. Thank you! Sub'd and liked!

  • @Tikodev
    @Tikodev 4 роки тому +15

    Yes please do a full fledged tutorial series on this! I would love to see how you make cars interact with pedestrians and traffic signs!

  • @workflowinmind
    @workflowinmind 4 роки тому +3

    Man, I discovered your channel yesterday while looking at how to extend the Timeline! Since then the YT algo has fed me with 5 other of your videos, and I absolutely love your way of teaching, some might not realize the amount of work behind these but I'm very impressed. Thanks a lot.

  • @STARmod
    @STARmod 2 роки тому +2

    Still waiting the sequel to this one, such a perfect video, the topic of npc behavior and population in games is so good, i love this, thanks bro!

  • @jonesbbq307
    @jonesbbq307 4 роки тому +226

    GTA V's traffic system must have a parameter called "stupidity" set to 200000

    • @selvesa
      @selvesa 4 роки тому +22

      It actually does!
      Devs made the AI capable of making bad decissions and failing in porpouse cause, as u know, idiots do exist in real life too. Sadly, as u also commented, that chance may be set to "2000000" cause it happens more often than it should x)

    • @abigweed1811
      @abigweed1811 4 роки тому +1

      @@selvesa You're talking about GTA V and if their traffic system has a stupidity ratio?
      Ofcourse it does, that's a really obvious question lmfao

    • @deei5130
      @deei5130 4 роки тому

      @@selvesa Aaand literally all of peds have stupidity assign to them

    • @suicidalbanananana
      @suicidalbanananana 4 роки тому +6

      static BOOL IS_SOCCERMOM_AI() { return invoke(TRUE); }

    • @futuremapper_
      @futuremapper_ 4 роки тому

      @@suicidalbanananana what

  • @rutchjohnson
    @rutchjohnson 4 роки тому +27

    Really would like to see the car traffic system you had in mind :)

  • @BrokenPuzzle03
    @BrokenPuzzle03 4 роки тому +2

    Holy shi! This is probably a Gem of a tutorial! Can't believe It took me years to find this type of quality content

  • @davidzap
    @davidzap 4 роки тому +5

    2:08 When you said that I knew that this vid waqs going to be amazing! :D thanks

  • @jkjaniszewski
    @jkjaniszewski 4 роки тому +3

    Bro, the quality! I wish every tutorial was so on point as yours. Subbed and good luck with yt career!

  • @Demotana
    @Demotana 4 роки тому +1

    This closed a huge gap in knowledge within only 18 minutes, amazing. Thank you for sharing

  • @bunggo9914
    @bunggo9914 3 роки тому

    your contents are so helpful, I get to learn advanced stuffs that nobody else provides :)

  • @Oxmond
    @Oxmond 4 роки тому +7

    Wow! Great tutorial! A rather complicated subject perfectly reviewed in under 20 minutes 👍🤓

  • @argentiignis
    @argentiignis 2 роки тому

    I am forever grateful for this tutorial

  • @CodeGaff
    @CodeGaff 5 років тому +3

    Fantastic video as always Matt!
    I love your teaching process. Looking forward to seeing your channel blow up! :)

  • @TrueIndian
    @TrueIndian 5 років тому

    Sweet , concise and on point. Where you don't leave the viewer with some dead end but with new possibilities.Please make more videos

  • @newbquesttv
    @newbquesttv 5 років тому +4

    Great video Matt! Super cool stuff and really clearly explained. I'd be interested to see this interacting with Navmesh, which might also address some of the inter-person collision stuff. Great work!

    • @GameDevGuide
      @GameDevGuide  5 років тому +2

      Thanks Matt. Yup, I avoided navmesh for sake of simplifying the contents however I'm intending to cover it in the sequel video extending this system.

  • @Husmanmusic
    @Husmanmusic 2 роки тому

    This is such an amazing video, one issue I've run into though is when you pause your game. There will be a NAN position error. I've found a workaround for this by not putting the timescale to 0 but to 0.001f. It's not the most beautiful fix but hey it's something.

  • @ujjawaltyagi9481
    @ujjawaltyagi9481 4 роки тому +1

    I just discovered your Channel. You are a life saver

  • @AyazSardar
    @AyazSardar 4 роки тому +2

    This is exactly what I was looking for. Thank you!

  • @tientam779
    @tientam779 4 роки тому

    Really nice work. I love both how thought out the traffic tool is and also you covering how to create the UI for it. Definitely create a sequel to expand on the traffic system like you mentioned.
    If you would consider doing more tutorials that cover the basics of setting up an editor UI like the one you have here, I think a lot of people would be interested in that as well.

  • @pupilmusic3197
    @pupilmusic3197 4 роки тому

    As someone who knows game development but not c# this is a perfect way to help make crash coursing the language fun! I have to subscribe now lol.

  • @mxnxkx-ez5je
    @mxnxkx-ez5je 9 місяців тому

    really good guide! thanks for sharing!

  • @HeizenblogGaming
    @HeizenblogGaming 5 років тому

    This is one of the best examples I have seen, please continue this.

  • @xenmckinzee8348
    @xenmckinzee8348 5 років тому

    I'm really loving all your videos. Very informative with out holding your hand. Please keep up the great work. :)

  • @michaelshollaj6428
    @michaelshollaj6428 Рік тому

    Subscribed immediately, great job

  • @VHShark
    @VHShark 5 років тому

    Love your videos man and I can't wait to see more tutorials from you ;)

  • @trumanboone5395
    @trumanboone5395 5 років тому +50

    This video is amazing! Thank You!
    Would you mind doing a video going over the CharacterNavigationController?

    • @softeuwu
      @softeuwu 5 років тому +7

      Agreed! Please go over the CharacterNavigationController

    • @MohammadFaizanKhanJ
      @MohammadFaizanKhanJ 4 роки тому +1

      Not much difficult to write the script as 90% script has shared in the tutorial! I used this into my follow tut vid.

    • @cassidynoble5466
      @cassidynoble5466 4 роки тому +19

      Here is what I came up with. I don't know if you're still working on the project, but maybe there are others that could benefit. I got to this by what he showed on screen in the script editor and what public variables were available in the Unity Inspector (currently, I don't have animations on my character so I cut those lines)-
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      public class PedestrianCharacterController : MonoBehaviour
      {
      public Vector3 destination;
      Vector3 lastPosition;
      public bool reachedDestination;
      public float stopDistance = 1;
      public float rotationSpeed;
      public float minSpeed, maxSpeed;
      public float movementSpeed;
      Vector3 velocity;
      private void Start()
      {
      movementSpeed = Random.Range(minSpeed, maxSpeed);
      }
      private void Update()
      {
      if (transform.position != destination)
      {
      Vector3 destinationDirection = destination - transform.position;
      destinationDirection.y = 0;
      float destinationDistance = destinationDirection.magnitude;
      if (destinationDistance >= stopDistance)
      {
      reachedDestination = false;
      Quaternion targetRotation = Quaternion.LookRotation(destinationDirection);
      transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
      transform.Translate(Vector3.forward * movementSpeed * Time.deltaTime);
      }
      else
      {
      reachedDestination = true;
      }
      velocity = (transform.position - lastPosition) / Time.deltaTime;
      velocity.y = 0;
      var velocityMagnitude = velocity.magnitude;
      velocity = velocity.normalized;
      var fwdDotProduct = Vector3.Dot(transform.forward, velocity);
      var rightDotProduct = Vector3.Dot(transform.right, velocity);
      }
      }
      public void SetDestination(Vector3 destination)
      {
      this.destination = destination;
      reachedDestination = false;
      }
      }

    • @ianfarrell1182
      @ianfarrell1182 3 роки тому +1

      @@cassidynoble5466 Thank you so much, you saved me hours of confusion.

    • @namanjhamb5700
      @namanjhamb5700 3 роки тому +1

      @@cassidynoble5466 Thank you for this! Also, do you have an idea of decelerating and accelerating the object at each waypoint to make it similar to vehicle behaviour?

  • @kawaiistef
    @kawaiistef 4 роки тому

    Thank you ! You give a lot of very effective and new advices, compared to other guys, that’s very nice.
    I learned a lot thanks to this tutorial, especially the way to make tools for easily editing a level.

  • @LOLMAN836
    @LOLMAN836 3 роки тому

    Great video! hopefully the tutorials about traffic system will continue ;)

  • @MatrixQ
    @MatrixQ 3 роки тому

    This is just absolutely brilliant. Thank you so much.

  • @pennaverdeful
    @pennaverdeful 3 роки тому

    That's awesome, thank you for this video!
    Please do another one with more complex behaviour, or even cars! :)

  • @burner3388
    @burner3388 4 роки тому

    Very good quality tutorial! Expanding on this topic would be awesome

  • @adslpiulentoditalia2545
    @adslpiulentoditalia2545 Рік тому

    This is something unbelievable. Thank you very much!!

  • @jaythans
    @jaythans 4 роки тому +3

    This is a really cool tutorial, a lot of things I didn't even know.
    When you created a random direction at 12:18, I'm pretty sure you can just leave out the f in the random.range values, so
    it will return an integer and you won't need to RoundToInt ^^
    Edit: You got a like

  • @crookiemonzter1538
    @crookiemonzter1538 4 роки тому

    Amazing. Instantly subscribed. Thank you so much. Please keep making awesome videos.

  • @simoncodrington
    @simoncodrington 4 роки тому

    Great video mate. I've worked on a similar system but ended up using basic gizmos, having these unique editor controls would of made my work much easier 😮
    Love your work!

  • @jdonaldsontcs
    @jdonaldsontcs 5 років тому

    wow, this is awesome dude. looking forward to going through your other videos!

  • @NiclasGleesborg0
    @NiclasGleesborg0 5 років тому

    Great video. And cool system.

  • @arongilli7415
    @arongilli7415 4 роки тому +1

    Thank you very much! Really useful, please continue :D

  • @noodle-eater
    @noodle-eater 4 роки тому

    This is cool dude, your video is awesome. I learn a lot

  • @mattbridges385
    @mattbridges385 4 роки тому

    Dude, Fantastic work!

  • @tdr0794
    @tdr0794 5 років тому

    very, very useful content. Great video!
    Keep it up Matt.

  • @ianfarrell1182
    @ianfarrell1182 3 роки тому

    Brilliant asset, thank you for sharing your skills for free.

  • @martynawasiluk1405
    @martynawasiluk1405 4 роки тому

    This is AWESOME!

    • @sajuthomas09
      @sajuthomas09 4 роки тому

      HEY PLZ GIVE THE navigation controller full code plz

  • @MohammadFaizanKhanJ
    @MohammadFaizanKhanJ 4 роки тому

    Thanks for a wonderful video! Indeed it is a great starting point for us to build a more complex system.

  • @shojintam4206
    @shojintam4206 Рік тому

    3:04 WaypointManagerWindow
    15:56 Entry node, exit node.

  • @RunyCZ
    @RunyCZ 4 роки тому +3

    0:15 actually they survive the fall :D If you look at them, they never fall down, but instead, they are webbed to the wall

  • @kasit008
    @kasit008 4 роки тому

    You've earned a sub! Great content!

  • @nashiruddin3543
    @nashiruddin3543 4 роки тому +3

    He - creating custom editor to make waypoint
    Meanwhile Ctrl - D :- I am joke to you

  • @meta-andy
    @meta-andy 4 роки тому

    You did a really good job!! Thanks a lot.

    • @sajuthomas09
      @sajuthomas09 4 роки тому

      HEY PLZ GIVE THE navigation controller full code plz

  • @razzraziel
    @razzraziel 5 років тому +1

    nice vid and good/fast presentation. subbed. you can do mini series on same topic with 2 or 3 videos max. so you can dive into details and also change the topic shortly after the series for non interested viewers. for example, this video topic is good but it feels like it cut half. thanks.

  • @lisssner
    @lisssner 3 роки тому

    Great video, thank you

  • @spikechu
    @spikechu 2 роки тому

    Would love to see an expanded version of this.

  • @mqoding
    @mqoding 5 років тому +2

    Great channel, lots of very useful content here. Could you do a tutorial on turn-based games? It's a topic that isn't covered in tutorials a lot so it will definately have value I think. I'm extremely interested in a system as used in the game "Dead in Bermuda".
    Keep up the good work!

  • @GamesInHouse
    @GamesInHouse 5 років тому +1

    Very comprehensive video, thanks a lot for sharing. Are you planning on sharing the project? The only thing that I would like to see is the behavior of pedestrians waiting by the traffic light when red. I know you could change the range to zero so pedestrians don't cross, but that wouldn't be the natural behavior. The expectation would be that the pedestrian chooses to head across but has to wait for the green light.

  • @airtakusa
    @airtakusa 5 років тому

    fantastic tutorial thank you so much

  • @AbhayKumar-kb8tv
    @AbhayKumar-kb8tv 5 років тому +10

    Use should make probably more videos like this, can you make video on any of the topic like realistic combat and pakour

  • @prathmeshnavik5094
    @prathmeshnavik5094 4 роки тому

    LOVE IT!!!!!!!! Thanks so much bro

  • @Muthwill
    @Muthwill 4 роки тому

    Traffic sounds really interesting! :)

  • @ssanimations4785
    @ssanimations4785 4 роки тому

    I love it please make more videos and if possible can you make a video about how to add behaviour to the pedestrians

  • @christopherjr7189
    @christopherjr7189 5 років тому +1

    This was amazing, how come you have so few subscribers?!? I only just found your channel and I instantly subscribed, I hope to see more videos of yours in future!

  • @Patrick-ui4ls
    @Patrick-ui4ls 4 роки тому

    Amazing tutorial!

  • @Definitely_a_Fox
    @Definitely_a_Fox 5 років тому

    This tutorial is neat! It would be cool to see a few more things!
    In a few demonstrations, it showed the Eric's spawning wherever they wanted to, but seeing them spawn on the path would be cool!
    Also, I saw him cutting corners a little bit.
    Perhaps we could also create a path that can only be travelled one way, so all of the traffic goes in one direction.
    Also, a button to automatically close a path would be neat too!

    • @dmas7749
      @dmas7749 Рік тому

      it would be weirder if they WEREN'T cutting corners

  • @youtuber9991
    @youtuber9991 3 роки тому

    Did you ever make a video on vehicle traffic? Would love a detailed guide on that especially on a multi-lane road

  • @AmanKumar-tu2og
    @AmanKumar-tu2og 5 років тому +1

    Awesome video Eric! This can be extended into various possibilities. If it's possible please upload the project repo on github. Even the project without this demo scene will work too. Thanks!

  • @thepresidentgaming404
    @thepresidentgaming404 4 роки тому

    Keep up the good work.You've got new Subscriber

  • @Atulkumar-sz6tg
    @Atulkumar-sz6tg 4 роки тому

    This is just amazing..

  • @bluntfist
    @bluntfist 4 роки тому

    At 9:00, I think you forgot the line
    newWaypoint.previousWaypoint = selectedWaypoint;
    Fantastic video, though! This waypoint stuff is extremely useful.

  • @ugurtanerkazan9046
    @ugurtanerkazan9046 4 роки тому

    I would love to see more!

  • @jorisslagter
    @jorisslagter 4 роки тому

    Would love to see more! 🤓

  • @jeremyguay3675
    @jeremyguay3675 4 роки тому

    Where to say but i dont care about trafic, this video is so useful for rts games
    Love it

  • @BAHGaming
    @BAHGaming 5 років тому

    Very cool. Well done!

  • @wheatpenguin2311
    @wheatpenguin2311 5 років тому +1

    Phenomenal video!

  • @chris.davidoff
    @chris.davidoff 4 роки тому

    This is really cool!

  • @bz9894
    @bz9894 4 роки тому

    great job thank you very much good luck

  • @3wGaming
    @3wGaming 4 роки тому +1

    I wish this was uploaded earlier! I already made my own traffic system. It is almost similar to yours except yours does not spawn depending on player position yet

  • @hostmeto
    @hostmeto 4 роки тому +2

    How did you make the character controller?

  • @simonhagfalk
    @simonhagfalk 4 роки тому

    Would love to see one with vehicles!

  • @halivudestevez2
    @halivudestevez2 4 роки тому

    high level deep knowledge ...

  • @psyneur9182
    @psyneur9182 4 роки тому

    I'd be interested to see how this would look if you use the waypoint system as one factor in some sort of boid controller. Then, you could add more clever avoidance of other pedestrians, random grouping of pedestrians for "friends" walking together (via attraction/speed matching), and I'm sure there's other things you could do with it. I might play around with this.

  • @ithanhunt3250
    @ithanhunt3250 4 роки тому +2

    *that trembling of the characters when they collide is horrendous*

  • @ab-yf6jm
    @ab-yf6jm 4 роки тому

    Cool.This video is very useful

    • @sajuthomas09
      @sajuthomas09 4 роки тому

      HEY PLZ GIVE THE navigation controller full code plz

  • @lautinus9604
    @lautinus9604 5 років тому

    Amazing Video!

  • @MrKytman
    @MrKytman 4 роки тому

    Amazing, Just amazing!

  • @definitelygamedev5821
    @definitelygamedev5821 4 роки тому

    If you pay attention in Spider man you can actually see that the enemies you throw off building actually get attached to the side of the building by a web bomb or something

  • @1202loki
    @1202loki 4 роки тому

    Feels like cyberpunk npcs to me, great job!

  • @softeuwu
    @softeuwu 5 років тому +2

    Can you please share or do a guide for Character Navigation Controller Script? Thanks

  • @CasaSoy
    @CasaSoy 5 років тому +6

    This was such an educational video and it helped me understand much more about programming and what can be done with Unity. I'm still getting errors though and can't figure out why. I think something was missed in the character navigation script that I can't catch with the pause button. Would it be possible to make the scripts available somehow? Thank you!

    • @asclepiiusunknown1090
      @asclepiiusunknown1090 4 роки тому

      Yes PLEASE

    • @MohammadFaizanKhanJ
      @MohammadFaizanKhanJ 4 роки тому +1

      Actually he has shared the script of navigation controller! Some additional information required. It will be best of game Dev guide share us the link of Script. Thanks

  • @supertaurus2008
    @supertaurus2008 5 років тому

    Amazing...well done and very crisp tutorial..probably if you could teach c# I think everyone will learn it clearly..from your tuts

  • @andersnissen3062
    @andersnissen3062 4 роки тому

    Do you plan to do a follow up on this video? It would be great to learn how to add cars to the scene as well.

  • @VaupellGaming
    @VaupellGaming 4 роки тому

    Great video, but did you ever get back to look into how to interact with vehicles and pedestrians together as you mentioned at the end?

  • @abjoern
    @abjoern 4 роки тому +2

    14:05 whta that ternary expressions really necessary? Is it for readability?

    • @williamscott3673
      @williamscott3673 4 роки тому +3

      Good question. I learned how to program myself. Once, in highschool computer science class, I used a Ternary expression in my project that I then submitted to my teache. The next day I walk into class and he goes "Oh, Hey! I saw you used a Ternary expression in your code." Me, being self taught, didn't know it was called a ternary expression so I reply "What? What is a ternary expression?" He instantly started accusing me of cheating - copying code from the internet. Oh ternary expressions, the name that nearly got me an F on a project grade. I ended up getting a 101. Cheers!

    • @3wGaming
      @3wGaming 4 роки тому

      Lol what is it

  • @499268003
    @499268003 4 роки тому +1

    CDPR like "Write that down! Write that down"

  • @fcf8269
    @fcf8269 4 роки тому

    Got the full screen of the controller for the crowd mesh? It seems that you just show few lines of it. Awesome tutorial; would love to see how did you solve the issue with car jerking around while calculating collision among each other and how to make them move realistically.

  • @Odinlevi
    @Odinlevi 3 роки тому +2

    A small mistake, not gonna check if it was mentioned in comments. The way Random.Range(minIncusive, maxExclusive) works is first number will be in this range and the second will NOT. So in WaypointNavigator it should have been (line 35): currentWaypoint = currentWaypoint.branches[Random.Range(0, currentWaypoint.branches.Count)];
    In any other way the last branch will not ever been chosen no matter what.
    Also, I just found out it isn't really supportive of path branching with more than just one branch, sadly :(
    Not very good at maths and nodes, trees and so on, but I believe that is what really should be used here, no just "previous and next node"

  • @m.shcherbakov
    @m.shcherbakov 4 роки тому

    You are Amazing!