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

    • @ahmedaghadi8281
      @ahmedaghadi8281 3 ปีที่แล้ว

      @@user-de9gl3qw6f use bolt in unity

  • @BimzyDev
    @BimzyDev 3 ปีที่แล้ว +4

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

  • @lee1davis1
    @lee1davis1 3 ปีที่แล้ว +1

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

  • @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!

  • @-.._.-_...-_.._-..__..._.-.-.-
    @-.._.-_...-_.._-..__..._.-.-.- ปีที่แล้ว

    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!

  • @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!

  • @StellarMirage
    @StellarMirage ปีที่แล้ว

    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! :)

  • @kyleb104
    @kyleb104 5 หลายเดือนก่อน

    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.

  • @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 ☺️☺️

  • @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!

  • @hamza-trabelsi
    @hamza-trabelsi 3 ปีที่แล้ว

    Man you are the best

  • @madhusudanpanda6396
    @madhusudanpanda6396 3 ปีที่แล้ว

    Superb

  • @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...

  • @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.

  • @mayank4687
    @mayank4687 3 ปีที่แล้ว

    0 dislikes very cool!

  • @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 th-cam.com/video/mNoyPz3LCy0/w-d-xo.html

  • @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

  • @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

  • @oppadasbatatas8129
    @oppadasbatatas8129 3 ปีที่แล้ว

    Nice!!! like

  • @roshanthapa1297
    @roshanthapa1297 3 ปีที่แล้ว

    Good 👍

  • @DARamosYT
    @DARamosYT ปีที่แล้ว

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

  • @unoriginalcringygaming3002
    @unoriginalcringygaming3002 3 ปีที่แล้ว

    Nice

  • @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 ปีที่แล้ว

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

  • @gamermine2006
    @gamermine2006 3 ปีที่แล้ว

    U should make tutorial vehicular combat like twisted metal

  • @bakartu
    @bakartu 10 หลายเดือนก่อน

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

  • @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

  • @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?

  • @theturkish1373
    @theturkish1373 3 ปีที่แล้ว

    great

  • @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

  • @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.

  • @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.

    • @illuzorr6134
      @illuzorr6134 2 ปีที่แล้ว

      i am fixed all my bugs

  • @ahmedaghadi8281
    @ahmedaghadi8281 3 ปีที่แล้ว

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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      It's here th-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.

  • @skulfio5179
    @skulfio5179 3 ปีที่แล้ว +1

    Police Obstacle Avoidance Please

  • @MDProgramming
    @MDProgramming ปีที่แล้ว

    Yep

  • @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

  • @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

  • @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
      th-cam.com/video/mONHucoYASU/w-d-xo.html
      th-cam.com/video/0QU0yV0CYT4/w-d-xo.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?

  • @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

  • @brandonpetroski6663
    @brandonpetroski6663 3 ปีที่แล้ว +2

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

  • @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 😆

  • @stealthinator5774
    @stealthinator5774 3 ปีที่แล้ว

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

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 ปีที่แล้ว

      I would but dark theme burns my eyes

  • @alword
    @alword 3 ปีที่แล้ว

    Cyberpunk devs: 📝

  • @diliupg
    @diliupg 3 ปีที่แล้ว

    scripts have errors. can't attach to cars.

  • @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

  • @KwissBeats
    @KwissBeats 2 ปีที่แล้ว

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

  • @Emperors_A7MET
    @Emperors_A7MET 3 ปีที่แล้ว

    Love from pakistan

  • @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 th-cam.com/video/2X5m_nDBvS4/w-d-xo.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"

  • @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

  • @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

  • @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.