Simple Car AI Driver in Unity!

Поділитися
Вставка
  • Опубліковано 19 січ 2021
  • ✅ Get the Project files and Utilities at unitycodemonkey.com/video.php...
    🌍 Get my Complete Courses! ✅ unitycodemonkey.com/courses
    👍 Learn to make awesome games step-by-step from start to finish.
    Let's build a Simple Car Driver AI
    Great for any Driving or Racing Game where you want a Car to go to a certain position
    Patreon Sponsor: XR Bootcamp
    xrbootcamp.com/deep-dive-imme...
    Use coupon CM10 for a 10% discount on this highly recommended Master Class.
    I made a RACING RTS! (Mix and Game Jam 2020)
    • I made a RACING RTS in...
    AI Learns to Drive a Car (Unity ML-Agents)
    • AI Learns to Drive a C...
    🌍 Get Code Monkey on Steam!
    👍 Interactive Tutorials, Complete Games and More!
    ✅ store.steampowered.com/app/12...
    If you have any questions post them in the comments and I'll do my best to answer them.
    🔔 Subscribe for more Unity Tutorials / @codemonkeyunity
    See you next time!
    📍 Support on Patreon / unitycodemonkey
    🤖 Join the Community Discord / discord
    📦 Grab the Game Bundle at unitycodemonkey.com/gameBundl...
    📝 Get the Code Monkey Utilities at unitycodemonkey.com/utils.php
    #unitytutorial #unity3d #unity2d
    --------------------------------------------------------------------
    Hello and welcome, I am your Code Monkey and here you will learn everything about Game Development in Unity 2D using C#.
    I've been developing games for several years with 7 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
    You can see my games at www.endlessloopstudios.com
    --------------------------------------------------------------------
    - Website: unitycodemonkey.com/
    - Twitter: / unitycodemonkey
    - Facebook: / unitycodemonkey

КОМЕНТАРІ • 109

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  3 роки тому +7

    🌐 Have you found the videos Helpful and Valuable?
    ❤️ Get my Courses unitycodemonkey.com/courses or Support on Patreon www.patreon.com/unitycodemonkey

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

    I'm loving the great variety of content on your channel! 😀

  • @BlueGooGames
    @BlueGooGames 3 роки тому +14

    Brilliant as usual! I’ve been working on a space ship AI for our game using pid controllers and raycasts and it’s pretty fun!! 😀

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

      Nice! I hope your development is going well!

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

    Adddd to my unity must watch playlist. A lot of great logic here thanks

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

    💬 Let's build a Simple Car Driver AI
    Great for any Driving or Racing Game where you want a Car to go to a certain position
    I used this when making my Racing RTS ua-cam.com/video/mNoyPz3LCy0/v-deo.html

  • @dartutorials7859
    @dartutorials7859 3 роки тому +12

    I love AI stuff! I also do a lot of AI things in unity lately i work with procedural generation and AI its so much fun! 👍👍

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

    your tutorials are really useful! ty!

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

    Awesome! Thanks for sharing this with everyone!

  • @-.._.-_...-_.._-..__..._.-.-.-

    Man, I was trying to use NavMesh for the whole thing and pulling my hair out. I make things too hard for myself sometimes. Thank you for steering me back on track!

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

    Thanks Code Monkey!! This is so much better and more customizable than ML. Forget ML and make your own. I very much needed the how to steer part. I wasn't able to get it. Thanks Code Monkey for helping me complete racing project :)

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

    Nice, thank you! This is helping me make Ai cars in my bike game

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

    Great video man, the tutorial is really awesome. By the way can you make some tutorials on procedural animation. There are not much tutorial about this topic in the internet.

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

    nice tut thanks u so much ez and useful :3

  • @chidebenosiri4662
    @chidebenosiri4662 3 роки тому +8

    Thank you for the tutorial, in Unity 2020.2.2f1, my car was experiencing an issue whereby the car would be steering and not going straight to the point. I fixed with this:
    if (AngleToDir == 0 || (AngleToDir < 10 && AngleToDir > -10))
    {
    TurningAmount = 0;
    }
    I gave the car a range between 10 and -10, and if it is in between the range, it should not steer, also if the AngleToDir is 0, then it shouldn't steer. Hope this helps!

    • @gustavfranklarsen908
      @gustavfranklarsen908 Рік тому +1

      I was experiencing the same issue, and was expecting that I might have to make the car "less sensitive" to the angle - this solution worked perfectly, so thanks a lot! :)

  • @hamza-trabelsi
    @hamza-trabelsi 3 роки тому

    Man you are the best

  • @kyleb104
    @kyleb104 6 місяців тому

    One small suggestion is to change turning to an inverseLerped value of angleToDir. Otherwise it will be constantly be making full corrections to the left or right, which will slow the vehicle to a halt if you're using wheel colliders with sideways friction.

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

    Superb

  • @user-xl8nx4hm8i
    @user-xl8nx4hm8i 3 роки тому +4

    you can multiply speed by dot product so they will make sharper turns

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

      Oh that's interesting, didn't think to use that one

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

      That's awesome!

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

    Can I ask about the PC requirements to run such learning simulations? How long such example could take? Is there a way to benchmark mark and understand what type of hardware I need specifically for AI simulations? Like Processor, Ram and GPU? Appreciate your great and wonderful contents ☺️☺️

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

    This is great. Can I use it in another game engine also could you add a to use context based steering for the car to avoid other cars?

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

      Sure you can implement that same logic in a different engine, in the end it's all math.

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

    You should make a multiplayer tutorial

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

    Instead of doing a Vector.distance couldn't you use the dirToMovePosition sqrMagnitude or magnitude before normalizing? Would this be better or equivalent in performance?
    Thanks for the awesome video.

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

      Sure that would work. Highly unlikely to have any noticeable performance impact unless you have thousands of AI cars.

  • @elektra81516
    @elektra81516 3 роки тому +20

    CDProjekt Red: "I'll pretend I didn't see that"

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

      it takes a little more work than that LOL

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

      @@SubjektDelta but he is only o e person xD

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

      @@NAME494 I guess you have never worked in a big game dev company

    • @a.thiago3842
      @a.thiago3842 2 роки тому

      HAHAHAHAHAHAHAA Excellent. Unfortunatelly most of people doesn't understand irony. ....

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

    0 dislikes very cool!

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

    Good 👍

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

    Nice!!! like

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

    Nice

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

    U should make tutorial vehicular combat like twisted metal

  • @gustavfranklarsen908
    @gustavfranklarsen908 Рік тому +1

    Great tutorial, this was literally exactly what I was looking for! Perfect for simple racing enemies :D My only comment would be that I had a minor issue with the car turning left/right all the time and never going completely straight (sort of zig-zagging towards the target). Chidebe Nosiri pointed out a solution that seems to work for that, by simply making the car less sensitive to the angles. Once again, great video!

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

      Thats dependet on the driving phisics you have, the more arcady and stable, the more the AI will be able to handle it stable!

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

      Instead of an input 1f you can create a dynamic input by divindng the angleToDir/70f so depending on how sharp the angle is it turns more or less wich looks smoother

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

    great

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

    Hello Code Monkey! I have a question for you, i thank you so much for this tutorial i learn to make something similar, but when my car is following the target, the car start to shake like if his turnAmount was to -1 to 1 to -1 to 1 everytime , you know how i can solve this?

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

      Calculate the dot product and define a certain tiny minimum amount where below that you don't turn, it will prevent those micro adjustements.

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

      @@CodeMonkeyUnity thank you bro, you are awesome, dont let try be better♡ greetings from argentina

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

    Please help. For some reason my angleToDir calculation keeps oscillating very quickly between the same angle of a positive and negative value. I have debugged all the parameters within the equation and I still cannot figure out why this is happening...

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

    Yes....very simple....

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

      ah yes, I could make this in my sleep while struggling with very basic movement

  • @Mikes-Code
    @Mikes-Code Рік тому +1

    Who remembers Carmaggedon?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Рік тому +1

      Awesome game! I definitely remember playing it as a kid, it was one of those "forbidden" games, kind of like GTA

    • @Mikes-Code
      @Mikes-Code Рік тому

      @@CodeMonkeyUnity I played the pixelated version, and back then was amazed with the graphics 😆

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

    Very helpful basis. Thinking of calling these ai drivers "monkeybrains".

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

    Police Obstacle Avoidance Please

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

    I have edited my comment. You are right. Thank you for your response.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Рік тому +1

      Uh? Adding support for elevation needs to be added to your Driver script, not the AI script which is what this video is about.
      The AI doesn't care if the target is above or below, it just goes forward, left and right. As long as your Driver script supports elevation this AI will get there.

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

    I think it's about time you switch to visual studio dark theme

  • @bakartu
    @bakartu 11 місяців тому

    I put the CarDriver on my car but it doesn't work. Do i need to add anything else?

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

    Did you removed the playlist which contains complete tutorial for beginners for unity?

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

      It's here ua-cam.com/play/PLzDRvYVwl53vxdAPq8OznBAdjf0eeiipT.html

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

      @@CodeMonkeyUnity Thx but when I search something like "Unity tutorial for beginners" then your playlist comes up which has more videos like more than 30 or something like that. Okay, no problem! You would have some issues with that playlist I guess.

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

    How can we just make the car move randomly on the ground without any targetPoint or path to follow? Like a fake multiplayer game?

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

    Yep

  • @illuzorr6134
    @illuzorr6134 2 роки тому +1

    CarAi works strangely for me with blender models, they start to move sideways, there were also problems with scripts, but I fixed them. Can anyone please help? Is there another AI similar to this that is capable of avoiding obstacles for cars? I need for my rts.

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

    Cyberpunk devs: 📝

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

    I'm having two issues. Mouse3D and GameHandler don't exist in the current context

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

    Can someone help me?
    I used to play a game in my phone 5-6 years back. It was a roller coaster game with different levels. In levels some tracks are missing, some tracks fall when you pass of them and there are passengers who fall it you ride carelessly.
    If you know such a game, please tell me.

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

      I believe RollerCoaster Tycoon has some mobile version

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

    It won't let me download the files, its saying I never to validate my email..I've done that ages ago and there's no new email in my inbox?

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

      Maybe your mailer rejected a newsletter or reported it as spam, when that happens the email gets unvalidated to prevent it from sending emails to people who dont want them.
      Try adding contact@unitycodemonkey.com to your whitelist and request another validation

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

      @@CodeMonkeyUnity Its OK on the my PC ,need to wait for 7 days tho lol

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

    im trying to make this in 2D, and the car will just keep going backwards no matter where i place the target, is there a fix?
    edit: looks like it works on the z axis, ill see if i can solve it
    edit 2: ill leave this comment here for who does it in 2D, just change the forward in dot to up and it should work

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 роки тому +1

      Yes for 2D you need to convert the logic from XZ to XY

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

    Love from pakistan

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

    Does anyone know How I can try make game similar to Fire Emblem, I would like to try make a game with tose same machanics bit I don't know where to start. Dice I'm New to programming

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

      That's a pretty complex thing to do if you're new to programming, I covered a Grid Based Turn Battle System here
      ua-cam.com/video/mONHucoYASU/v-deo.html
      ua-cam.com/video/0QU0yV0CYT4/v-deo.html

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

      @@CodeMonkeyUnity Thanks brother, now I'm going to watch the videos to see if I get it, another question, do you know how I can make a button in the same action menu, that is, attack, special abilities, etc., that simply appears when my character has little life to transform?

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

    Though nice, I really do start to feel that the term AI (or Artificial Intelligence) is starting to lose its meaning. I guess that's always the case though in the context of showcasing some "basics". Weird though that we now start to consider ML to be what AI stands for :D

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

      You give it a target point and the car figures out what actions to take to get there, that's Artificial Intelligence, a non-intelligent entity couldn't figure that out
      The issue is that AI has become a buzzword that some people use in a much more limited way than the words actually mean.
      This is Classic AI, I've also made a Car Driver using Machine Learning AI ua-cam.com/video/2X5m_nDBvS4/v-deo.html

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

      ​@@CodeMonkeyUnity I guess what I was trying to say is: AI seems more automation than intelligence. Sure, there may be some wheight-based and/or priority based decision making along the way. Perhaps even complimented with some prng in there, but given the same parameters it will always behave the same way. It's a great way to approximate the appearance of intelligence. In that sense, I fully agree: It has become a buzzword. It was the best we could do at the time we started giving NPCs behaviours, but is it still accurate to call it AI, now that we have ML I wonder?
      MachineLearning, within the confines of its rules, can/will evolve and change its behavior over time. To me, that's much more "intelligent" than what we attribute to AI. What we call AI, is more a reflection of how much effort was put into the development of the behavioural rules of "automation".
      Anywho, I very much love your videos and my comment was not meant as a critique of the content. I was merely posting a thought that's been going through my head. I apologize if it came across as such.

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

      A friend of mine once said:" AI is just a bunch of ifs"

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

    scripts have errors. can't attach to cars.

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

    why give the projectiles when it's incomplete/broken?

  • @EmreM.
    @EmreM. Рік тому

    whats inside the CarDriver script file? Could you share it?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  Рік тому +1

      It's included in the project files linked in the description. It basically just moves the car along the transform.forward and rotates that game object, it's pretty simple

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

    Hey brother please make a video on train androod controler with realistic acceleration and brake and orbit view+train selector and route selector

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

    how do i convert 2d platform to 8 directions

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

    How do you convert this project to mobile? Thanks

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 роки тому +1

      The car doesn't care what platform it's being used on, there's no input here, you can set the target position in any way

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

    ilk yorum

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

    so much hardcoding AAAAAHHHHH

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

      Really? You think this is hard? CM teaches the basic. Still, always to see other ways to do things.

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

      @@lee1davis1 hard coding = setting variables at runtime. for example the forwardAmount in the Update function.
      no hard coding would be referencing them outside of functions and then use the reference.

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

      What's hard about this one? It's all just a bunch of simple logic, it should be easy to follow along with the video

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

    you move too fast, talk too fast, don't explain things in multiple ways. for people like me in the #lowIqGang

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

      Take your time, this is your learning journey, use the pause button as much as you need, just focus on learning.

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

      @@CodeMonkeyUnity damn you handle that sort comments really well

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

    what is a GameHandler in CarDriver.cs

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

    #CodeMonkey estou usando unity 2022.2.6 e da erro Assets\CarDriverAI\Scripts\CarAITargetMouse.cs(13,40): error CS0103: The name 'Mouse3D' does not exist in the current context e Assets\CarDriverAI\Scripts\CarDriver.cs(100,43): error CS0103: The name 'GameHandler' does not exist in the current context
    criei private Mouse3D; e esses erros acima some e aparece outro Assets\CarDriverAI\Scripts\CarAITargetMouse.cs(10,20): error CS1519: Invalid token ';' in class, record, struct, or interface member declaration
    como resolver isso,por favor ajude-me.

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

      O Mouse3D foi criado aqui unitycodemonkey.com/video.php?v=0jTPKz3ga4w
      O ultimo erro, tens um ; num sitio onde não é suposto

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

      @@CodeMonkeyUnity obrigado por responder, desejo sucesso no seu canal.