💬 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 ruclips.net/video/mNoyPz3LCy0/видео.html
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!
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! :)
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!
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.
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 :)
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!
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
For driving you normally want Flow Field pathfinding, then the car just follows the flow field arrows But really any kind of pathfinding works, you just make the car turn left/right to go towards the next point in the Path
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...
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?
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.
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.
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.
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.
@@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.
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 ☺️☺️
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
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
That's a pretty complex thing to do if you're new to programming, I covered a Grid Based Turn Battle System here ruclips.net/video/mONHucoYASU/видео.html ruclips.net/video/0QU0yV0CYT4/видео.html
@@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?
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.
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
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
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
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 ruclips.net/video/2X5m_nDBvS4/видео.html
@@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.
@@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.
#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.
🌐 Have you found the videos Helpful and Valuable?
❤️ Get my Courses unitycodemonkey.com/courses or Support on Patreon www.patreon.com/unitycodemonkey
@@user-de9gl3qw6f use bolt in unity
💬 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 ruclips.net/video/mNoyPz3LCy0/видео.html
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!! 😀
Nice! I hope your development is going well!
I'm loving the great variety of content on your channel! 😀
Thank you for this tutorial. It has been very helpful for my commercial projects.
you can multiply speed by dot product so they will make sharper turns
Oh that's interesting, didn't think to use that one
That's awesome!
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! 👍👍
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!
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! :)
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!
Adddd to my unity must watch playlist. A lot of great logic here thanks
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.
your tutorials are really useful! ty!
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 :)
Awesome! Thanks for sharing this with everyone!
Nice, thank you! This is helping me make Ai cars in my bike game
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!
Thats dependet on the driving phisics you have, the more arcady and stable, the more the AI will be able to handle it stable!
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
CDProjekt Red: "I'll pretend I didn't see that"
it takes a little more work than that LOL
@@SubjektDelta but he is only o e person xD
@@NAME494 I guess you have never worked in a big game dev company
HAHAHAHAHAHAHAA Excellent. Unfortunatelly most of people doesn't understand irony. ....
I'm having two issues. Mouse3D and GameHandler don't exist in the current context
me too
and me
Also me
me as well
How would you go about integrating this with pathfinding? Ie if I have buildings in the way and I want the car to pathfind around them?
For driving you normally want Flow Field pathfinding, then the car just follows the flow field arrows
But really any kind of pathfinding works, you just make the car turn left/right to go towards the next point in the Path
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...
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?
Calculate the dot product and define a certain tiny minimum amount where below that you don't turn, it will prevent those micro adjustements.
@@CodeMonkeyUnity thank you bro, you are awesome, dont let try be better♡ greetings from argentina
Who remembers Carmaggedon?
Awesome game! I definitely remember playing it as a kid, it was one of those "forbidden" games, kind of like GTA
@@CodeMonkeyUnity I played the pixelated version, and back then was amazed with the graphics 😆
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.
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?
Sure you can implement that same logic in a different engine, in the end it's all math.
Man you are the best
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.
Sure that would work. Highly unlikely to have any noticeable performance impact unless you have thousands of AI cars.
nice tut thanks u so much ez and useful :3
I put the CarDriver on my car but it doesn't work. Do i need to add anything else?
0 dislikes very cool!
I have edited my comment. You are right. Thank you for your response.
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.
Police Obstacle Avoidance Please
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.
i am fixed all my bugs
Did you removed the playlist which contains complete tutorial for beginners for unity?
It's here ruclips.net/p/PLzDRvYVwl53vxdAPq8OznBAdjf0eeiipT
@@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.
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 ☺️☺️
How can we just make the car move randomly on the ground without any targetPoint or path to follow? Like a fake multiplayer game?
You should make a multiplayer tutorial
Superb
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?
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
@@CodeMonkeyUnity Its OK on the my PC ,need to wait for 7 days tho lol
U should make tutorial vehicular combat like twisted metal
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
That's a pretty complex thing to do if you're new to programming, I covered a Grid Based Turn Battle System here
ruclips.net/video/mONHucoYASU/видео.html
ruclips.net/video/0QU0yV0CYT4/видео.html
@@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?
I think it's about time you switch to visual studio dark theme
I would but dark theme burns my eyes
why give the projectiles when it's incomplete/broken?
What projectiles?
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.
I believe RollerCoaster Tycoon has some mobile version
Very helpful basis. Thinking of calling these ai drivers "monkeybrains".
whats inside the CarDriver script file? Could you share it?
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
Nice!!! like
Yes....very simple....
ah yes, I could make this in my sleep while struggling with very basic movement
scripts have errors. can't attach to cars.
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
Yes for 2D you need to convert the logic from XZ to XY
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
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 ruclips.net/video/2X5m_nDBvS4/видео.html
@@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.
A friend of mine once said:" AI is just a bunch of ifs"
Good 👍
Cyberpunk devs: 📝
Nice
Yep
how do i convert 2d platform to 8 directions
great
Hey brother please make a video on train androod controler with realistic acceleration and brake and orbit view+train selector and route selector
How do you convert this project to mobile? Thanks
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
Love from pakistan
ilk yorum
so much hardcoding AAAAAHHHHH
Really? You think this is hard? CM teaches the basic. Still, always to see other ways to do things.
@@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.
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
you move too fast, talk too fast, don't explain things in multiple ways. for people like me in the #lowIqGang
Take your time, this is your learning journey, use the pause button as much as you need, just focus on learning.
@@CodeMonkeyUnity damn you handle that sort comments really well
what is a GameHandler in CarDriver.cs
#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.
O Mouse3D foi criado aqui unitycodemonkey.com/video.php?v=0jTPKz3ga4w
O ultimo erro, tens um ; num sitio onde não é suposto
@@CodeMonkeyUnity obrigado por responder, desejo sucesso no seu canal.