Were you able to follow along? Here's the 'getIntersection' code for a quick copy-paste: function getIntersection(A,B,C,D){ const tTop=(D.x-C.x)*(A.y-C.y)-(D.y-C.y)*(A.x-C.x); const uTop=(C.y-A.y)*(A.x-B.x)-(C.x-A.x)*(A.y-B.y); const bottom=(D.y-C.y)*(B.x-A.x)-(D.x-C.x)*(B.y-A.y);
if(bottom!=0){ const t=tTop/bottom; const u=uTop/bottom; if(t>=0 && t=0 && u
I wanted to point out that drawing the car on the line after creating a new car will cause a crash because the rays haven't been put into the array yet, just remove that line and it works (drawing is done by animate loop anyway). Also a tip for beginners: create key binds to start and stop the game loop, that way if there's a loop crash you can stop the looping console text with the push of a button. Basically make a "running = true" type argument that you turn on and off, and check that for returning from the loop like this: if(!game.running) {return}
@@cloudzero2049 Yes, my code doesn't have that drawing after creating the car :-) many people missed the fact that I *moved* that line inside the animate function. I didn't copy it. Great idea for controlling the game like that!
11:44 As a real world autonomous car tester, smiled at this bit. So much of autonomy is object detection, and we've "cheated" here. :) Thanks a ton for these videos, Radu! Really enjoying this series!
Real autonomous car tester... O_O gulp! I've just checked your videos and get what you mean (subscribed btw). You're used to having image processing as a component in this. This is more like lidar and the road has some walls around it. But I may teach a basic image processing approach someday. Stay tuned! :-)
thanks alot ! i'm a beginner in programming world so i got confused in between in understanding which function is calling which function. Now im going to Draw a flow-chat just for better understanding😅
Hello. I finally understood the code. I also tried different experiments with sensors: their number, scope, range. I also experimented with the number of neurons and the number of hidden layers (grid depth). Now I clearly understand exactly how this type of neural network works (without the error feedback function). And that's what I see here as a problem that no one on the Internet can explain in simple language. We scatter random numbers and want them to be sorted out the way we need them. Of the 1,000 options, we like one or more winners and we inherit his gene. Heirs additionally receive up to 10% of mutations in their own genetics. However, we do not know how beneficial this mutation will be or how harmful it will be, because we are adding chaos to the genetic makeup again. We are making natural selection again. However, progress is often no longer happening. After all, there are times when you need to make a mutation of more than 10%. A mutation of 30-50% is very harmful to us, because it creates chaos that does not improve our results. Perhaps crossing genes from different isolated teams would help. Because I tried a track with random cars and my winner on a fixed track dies on a chaotic track.
Glad to hear you went through it :-) This is an introductory course, though, there are many methods for handling those things you describe here. Like, if you have a 'too good' car, but not 'perfect' it can mean you are stuck in a local optima, so, a drastic change would be needed, however, unlikely to happen if you just allow for considerable mutations. The mutation strategy I present here is one of many... and I also don't talk about the topology of the network (should we add / remove some nodes or layers, etc...). I recommend you check the NEAT scientific article I pointed to in the video. It may answer many of your questions! Thanks for showing so much interest in this :-)
@@Radu 🙏Thank you very much for the recommendations and for the wonderful full course ❤👍. You made a video with a soul. I continue to try to learn the language by stopping the video and translating every word I don't understand. You have a very clear pronunciation. It seems to me that I have a chance to learn the language, because I am 39 years old and it is difficult for me to force myself to study and my progress has stopped, and with you I see that I can learn the language to understand freely, at least in IT technology.
Cool! I've made 2 python versions as well. One with just tkinter and one with pygame. They tend to be slower than the JavaScript version for some reason. I'm curious if you'll have the same problem.
@@Radu I am doing it in tkinter, it does run with 70 fps capped right now, but you do see the aliasing edges of the car moving, and performance spikes every once in a bit, I’ll tell you about my results once everything is implemented
return touches.find(t => t.offset == Math.min(...touches.map(t => t.offset))); OR return touches.sort((a,b) => a.offset-b.offset)[0]; ? finding the minimum by a key is the same as returnign the 1st element of the sorted array by that specific key for the 1st method you basically run map ( create new array and requires 1 traversal) then calculate min ( another traversal ) then you must find the element ( another traversal) for the 2nd method simply sorting the array ( uses timsort ( mergesort+insertionsort) O(n*log n) //on Chromium based browsers )
Hi Radu, great content. I'm following along but my code breaks when I write on sensors.js: ctx.moveTo( this.rays[i][0].x, this.rays[i][0].y ); sensors.js:35 Uncaught TypeError: Cannot read properties of undefined (reading '0'). I tried troubleshooting if the rays array was working, and It was. I don't know what might be breaking the code.
12:41 When you put the parameters inside the push() it does not draw the road or the car but if I leave the push without parameters it shows me the road and the car all good but what should I put in the push(). Also thanks for the video it's 👍🏼.
Wouldn't it make more sense to give the borders a different color, or some property that makes them different, and have the sensor "see" that difference? That way, the sensor is not bound by its environment, and require that borders are defined in some way. I assume that's ultimately how you're going to handle detection of vehicles, so why not apply the same technique to road elements as well?
Hi, if I understand correctly, you mean to conclude based on the color of a pixel if something should be avoided or not? Interesting idea. I might try it someday. Might even be more efficient depending on how it's implemented. But here are some thoughts about the current approach: 1. We use segment intersection to a) implement the sensors, b) implement collision detection, c) make the sensors detect other cars in traffic. I made it in this way because I want to teach the idea of reusing a well built function / module. 2. This can be extended into segment vs. plane intersection to make the project work in 3D 3. We are building here very visual things... we'll even visualize the neural network later. But they are all for us and not for the system to work. It is possible to train the system without needing to displaying anything. Displaying takes extra resources and if the functionality would depend on it it can become expensive. Of course... this doesn't bother us here.
@@Radu I was more focused on the problem that the sensor must be aware of the car and the car must be aware of the road. They are tightly coupled, which may hinder extensibility.
@@coachtroop Ah, ok. I get it now. Now what will happen later is that the sensor gets separately the information from the traffic, so, another parameter... but what you suggest is that it should just get everything, but that each thing it sees has information whether it should be avoided or not. Makes sense and I think it would be better in that way. Thanks for the tip! But what I don't understand is how to avoid linking the sensor with the car?
@@Radu it's fine if the sensor is a member of the car, but it shouldn't have to know about the car to function, right? A digital thermometer doesn't need to know how its data is displayed, it just needs to tell the temperature accurately. Something else takes its data and puts it on a screen or makes a beep. I get the tutorial here is simplified. A 2d plane doesn't really offer much to distinguish a road from not road, or a lane marker from a border. We have colors, or maybe some pseudo-attributes to emulate the real world. I don't want to be too critical here. I have really enjoyed this series so far, and am greatly looking forward to learning more. I have enjoyed every one of your videos, and that includes this one. It just stood out as odd that a sensor would have such a huge dependency, as that likely doesn't reflect a real world application.
@@coachtroop Ok. I get it now. I think the code should be so that as the car location and angle changes, it needs to 'move' the sensor accordingly. Maybe by having a setter in the sensor object for those attributes... I think it's great that you comment like this. It may seem like a small thing, but if more of these cumulate it makes the code (and the tutorial) harder to understand overall, I think. Hope you'll enjoy the rest of the series!
Are comments still replied to on this video? I absolutely enjoy following along with this. I did run into an annoying snag with the controls being mixed up, however. When pressing either the left or right key, the element seems to move right no matter what. I threw in console.log statements on the left and right to make sure they aren't double called, but they seem to function fine. If the problem isn't in the controls, where could the error be?
Funny how many people find the problem right after writing the comment :-) There's also a discord linked on my channel banner. You can post questions and code there so I can have a look. I check it from time to time.
Hello! Than you very much for your help! I have a problem, my sensors just dont change color when they intersect with the boarders. I checked the code a few times, looked through all comments but didnt find anything the same, checked your code at the github, but cannot understand, what is the problem(( Thank you in advance!
Hmm... good idea. I'll make a video about this someday. But I try to explain it here, in words. So... the unit circle is a circle that has a radius of 1. We don't draw this circle anywhere. We just use it for calculating values. The full circle has 360 degrees or 2PI radians. The length of a circle is 2PI*R but since this one has R=1, the length is also 2PI. In a circle, sin^2(a)+cos^2(a)=1 for any angle 'a'. Cos is the x and sin is the y of the point on the circle that makes that angle 'a'. So, knowing any angle, you can get the x and value of the (so called) unit vector. A vector that has a length of 1 (the radius) and points at the given angle. If you multiply these x and y by some scaler (like 6) you will get a vector with a length of 6 (might be more useful because moving things by 1 pixel at each frame is quite slow). Hope this helps.
Oh man this one thing threw me off. If we want a spread of 45deg then why are we dividing PI / 4 and not PI / 8 ? We wouldn't have to divide by 2 in the lerp function. Edit: Ok my head isn't working. I assumed PI = 360 for some reason. Ehh. But why is 0 deg pointing upwards in 3:50 ? Why the unit circle is rotated here ? Edit some more: OK I went back to lecture 1 and I think I get it now.
Haha. Quite funny seeing your edits :-) I read your first comment (without edits), but didn't have time to reply until now. Yeah... the unit circle could have been explained better. Basically, car going upwards means angle zero for the car, and for the rays, straight ahead means zero. The sine and cosine are switched.
just asking what if you had one slightly longer range sensor that rotated constantly and once it notice an object it activates the other sensors so they didnt need to be on all the time?...i only ask if this is a good idea as i wanted to make a real life car(kids electric ride on car) so the computer would be small and not have a lot of computing power...do you think this way could help the program run better or by using all the sensor all the time would not lag the program?....these little cars are slow but the one im building has 36v hover board motors as i think you need proper high speed for the program to work properly....and yes i have a remote emergency off remote if anything goes wrong :)
I believe it would work. But if the 'rotating sensor' detects something, you should be able to know the angle and the distance away from the current location. Those are polar coordinates that you can convert to another format if needed, so you wouldn't need other kind of sensors really... it depends on the accuracy of this first sensor.
@@Radu Hey Radu! Greetings from Latvia! First of all, great series. Just amazing! So at 7:40 on my side, the issue was that ctx.moveTo(this.rays[i][0].x, this.rays[i][0].y); within Sensor > draw(ctx) was throwing 'undefined' error because this.sensor.update() was not called from car.js > update() and hence there was nothing in this.rays . So here fix was to add this.update() to Sensor's constructor. But! The interesting part is that at the end, my code was not working again. And now the fix was ... removing this.update() from Sensor's constructor. I am not good enough to explain all of this, but my guesses are - either I have something comepletly off somewhere (but I have rewatched some parts like 5x + checking against your GitHub) or maybe you cought your misplaced draw(ctx) in Sensor late enough that it was not an issue for your? My code is at: github.com/CurtisLV/Neural_Network_Car_JS
@@karlism.5604 I suspect that you may have had an extra call to car.draw(ctx); above the animate function. It would try to draw the rays before the update. Many people have had a similar issue because, I think, I make that change too fast in the video and I don't draw attention to it. Your error sounds similar, but hard to say since you tried so many things :-) Anyway, let me know if you still have some issues, and happy to hear you like the course!
Radu, great video. I am working my way through the code and got caught on a : sensor.js:40 Uncaught TypeError: Cannot read properties of undefined (reading '0') at Sensor.draw (sensor.js:40:29). I too added the this.update in the constructor of the sensor and it work fine. Did I miss something? Thanks again.
@@dukegard2504 I would say the same thing... You may have an extra car.draw(ctx); in main.js, somewhere above the animate function. If it's not that, can you send the code over so I can have a look?
I got a bit of errors when I was writing your code escpecially when we draw the sensors your code : ctx.moveTo( this.rays[i][0].x, this.rays[i][0].y ); ctx.lineTo( end.x, end.y ); ctx.stroke(); I had to put in an if stateme if(this.rays[i]){} to check if rays[i[ exist before accessing it properties because if I dont I get Uncaught TypeError: Cannot read properties of undefined (reading '0') Just putting this out incase some gets the same problem
Hmmm, could it be that you still have a car.draw(ctx); in main, above the animate function? I removed it from there in the video, but did it quite fast and many people didn't notice.
Thank you so much for this insight. I was getting the same error, and apparently, it is quite an exceptional one, so you were the only one to even mention it!
Were you able to follow along? Here's the 'getIntersection' code for a quick copy-paste:
function getIntersection(A,B,C,D){
const tTop=(D.x-C.x)*(A.y-C.y)-(D.y-C.y)*(A.x-C.x);
const uTop=(C.y-A.y)*(A.x-B.x)-(C.x-A.x)*(A.y-B.y);
const bottom=(D.y-C.y)*(B.x-A.x)-(D.x-C.x)*(B.y-A.y);
if(bottom!=0){
const t=tTop/bottom;
const u=uTop/bottom;
if(t>=0 && t=0 && u
I wanted to point out that drawing the car on the line after creating a new car will cause a crash because the rays haven't been put into the array yet, just remove that line and it works (drawing is done by animate loop anyway).
Also a tip for beginners: create key binds to start and stop the game loop, that way if there's a loop crash you can stop the looping console text with the push of a button. Basically make a "running = true" type argument that you turn on and off, and check that for returning from the loop like this: if(!game.running) {return}
@@cloudzero2049 great tips! Thank you.
@@cloudzero2049 Yes, my code doesn't have that drawing after creating the car :-) many people missed the fact that I *moved* that line inside the animate function. I didn't copy it.
Great idea for controlling the game like that!
Man, don't know why, but you make me remember Sheldon Cooper, I love your lesson.
Haha, ok :-) Thanks for watching!
Really nice. Thank Radu, a couple of hiccups coding along during the rays casting but overall great experience.
Glad to hear you got it to work in the end! I think this is the most confusing part in the series. So if you passed this one, you should be OK :-)
11:44 As a real world autonomous car tester, smiled at this bit. So much of autonomy is object detection, and we've "cheated" here. :)
Thanks a ton for these videos, Radu! Really enjoying this series!
Real autonomous car tester... O_O gulp!
I've just checked your videos and get what you mean (subscribed btw). You're used to having image processing as a component in this. This is more like lidar and the road has some walls around it. But I may teach a basic image processing approach someday. Stay tuned! :-)
@@Radu What we have now has been so helpful. You do you. Thanks for the support!
@@samreaves Sure :-)
YES! So excited to see this video uploaded! Keep up the good work Radu! :D
Thank you Aaron! :-)
Great tutorial Radu!
Multumesc :-)
thanks alot !
i'm a beginner in programming world so i got confused in between in understanding which function is calling which function. Now im going to Draw a flow-chat just for better understanding😅
Great! Good luck with that!
Excellent content, Radu! :) Keep up the great work!
Thanks Viorel!
Hello. I finally understood the code. I also tried different experiments with sensors: their number, scope, range. I also experimented with the number of neurons and the number of hidden layers (grid depth). Now I clearly understand exactly how this type of neural network works (without the error feedback function). And that's what I see here as a problem that no one on the Internet can explain in simple language. We scatter random numbers and want them to be sorted out the way we need them. Of the 1,000 options, we like one or more winners and we inherit his gene. Heirs additionally receive up to 10% of mutations in their own genetics. However, we do not know how beneficial this mutation will be or how harmful it will be, because we are adding chaos to the genetic makeup again. We are making natural selection again. However, progress is often no longer happening. After all, there are times when you need to make a mutation of more than 10%. A mutation of 30-50% is very harmful to us, because it creates chaos that does not improve our results. Perhaps crossing genes from different isolated teams would help. Because I tried a track with random cars and my winner on a fixed track dies on a chaotic track.
Glad to hear you went through it :-)
This is an introductory course, though, there are many methods for handling those things you describe here. Like, if you have a 'too good' car, but not 'perfect' it can mean you are stuck in a local optima, so, a drastic change would be needed, however, unlikely to happen if you just allow for considerable mutations. The mutation strategy I present here is one of many... and I also don't talk about the topology of the network (should we add / remove some nodes or layers, etc...). I recommend you check the NEAT scientific article I pointed to in the video. It may answer many of your questions! Thanks for showing so much interest in this :-)
@@Radu 🙏Thank you very much for the recommendations and for the wonderful full course ❤👍. You made a video with a soul. I continue to try to learn the language by stopping the video and translating every word I don't understand. You have a very clear pronunciation. It seems to me that I have a chance to learn the language, because I am 39 years old and it is difficult for me to force myself to study and my progress has stopped, and with you I see that I can learn the language to understand freely, at least in IT technology.
@@KlinovAS I am amazed you got this far without mastering the language. Keep up the great work :-)
Great video again, thank you so much!
Glad you enjoyed it!
doing all of this in python, translating everything from js to python, but this is so much fun and so much learning
Cool! I've made 2 python versions as well. One with just tkinter and one with pygame. They tend to be slower than the JavaScript version for some reason. I'm curious if you'll have the same problem.
@@Radu I am doing it in tkinter, it does run with 70 fps capped right now, but you do see the aliasing edges of the car moving, and performance spikes every once in a bit, I’ll tell you about my results once everything is implemented
@@thethirdeve5089 Slowdown starts to happen when more cars are optimized in parallel.
return touches.find(t => t.offset == Math.min(...touches.map(t => t.offset)));
OR
return touches.sort((a,b) => a.offset-b.offset)[0];
?
finding the minimum by a key is the same as returnign the 1st element of the sorted array by that specific key
for the 1st method you basically run map ( create new array and requires 1 traversal)
then calculate min ( another traversal )
then you must find the element ( another traversal)
for the 2nd method simply sorting the array ( uses timsort ( mergesort+insertionsort) O(n*log n) //on Chromium based browsers )
Correct! For small arrays like what we have here, sorting might be more efficient. But I don't recommend this practice in general.
Please make a playlist, so later i can access all video easily
Ok. I'll make it soon! Thanks for the idea :-)
There you go ua-cam.com/play/PLB0Tybl0UNfYoJE7ZwsBQoDIG4YN9ptyY.html
I swear I am not following the lessons just for the intro pun + song, but it is a factor :D!
:-))) haha
Hi Radu, great content. I'm following along but my code breaks when I write on sensors.js:
ctx.moveTo(
this.rays[i][0].x,
this.rays[i][0].y
);
sensors.js:35 Uncaught TypeError: Cannot read properties of undefined (reading '0'). I tried troubleshooting if the rays array was working, and It was. I don't know what might be breaking the code.
Once i write this code I can't find: car.sensor.rays[0][0].x on console. But if I comment I can find all the itens on car.sensor.rays
Could you share the code somehow? Like on my Discord, for example? (Link on my banner) Hard to say otherwise...
I'm also getting the same error even with the GitHub codes for this video. Did you manage to fix it?
@@IQmates I talked with radu and there was a duplicate on the animate() function on line 9 i think, I deleted it and it worked
@@kcshuffle Yes I saw one of his comments. There was a duplicate car.draw(ctx) on the main file which needed to be deleted.
Valeu!
Thanks :-)
12:41 When you put the parameters inside the push() it does not draw the road or the car but if I leave the push without parameters it shows me the road and the car all good but what should I put in the push(). Also thanks for the video it's 👍🏼.
Do you get any error in the console? I could have a look at the code if you share it somehow (like on my Discord server).
Wouldn't it make more sense to give the borders a different color, or some property that makes them different, and have the sensor "see" that difference? That way, the sensor is not bound by its environment, and require that borders are defined in some way. I assume that's ultimately how you're going to handle detection of vehicles, so why not apply the same technique to road elements as well?
Hi, if I understand correctly, you mean to conclude based on the color of a pixel if something should be avoided or not? Interesting idea. I might try it someday. Might even be more efficient depending on how it's implemented. But here are some thoughts about the current approach:
1. We use segment intersection to a) implement the sensors, b) implement collision detection, c) make the sensors detect other cars in traffic. I made it in this way because I want to teach the idea of reusing a well built function / module.
2. This can be extended into segment vs. plane intersection to make the project work in 3D
3. We are building here very visual things... we'll even visualize the neural network later. But they are all for us and not for the system to work. It is possible to train the system without needing to displaying anything. Displaying takes extra resources and if the functionality would depend on it it can become expensive. Of course... this doesn't bother us here.
@@Radu I was more focused on the problem that the sensor must be aware of the car and the car must be aware of the road. They are tightly coupled, which may hinder extensibility.
@@coachtroop Ah, ok. I get it now. Now what will happen later is that the sensor gets separately the information from the traffic, so, another parameter... but what you suggest is that it should just get everything, but that each thing it sees has information whether it should be avoided or not. Makes sense and I think it would be better in that way. Thanks for the tip!
But what I don't understand is how to avoid linking the sensor with the car?
@@Radu it's fine if the sensor is a member of the car, but it shouldn't have to know about the car to function, right? A digital thermometer doesn't need to know how its data is displayed, it just needs to tell the temperature accurately. Something else takes its data and puts it on a screen or makes a beep.
I get the tutorial here is simplified. A 2d plane doesn't really offer much to distinguish a road from not road, or a lane marker from a border.
We have colors, or maybe some pseudo-attributes to emulate the real world.
I don't want to be too critical here. I have really enjoyed this series so far, and am greatly looking forward to learning more. I have enjoyed every one of your videos, and that includes this one. It just stood out as odd that a sensor would have such a huge dependency, as that likely doesn't reflect a real world application.
@@coachtroop Ok. I get it now.
I think the code should be so that as the car location and angle changes, it needs to 'move' the sensor accordingly. Maybe by having a setter in the sensor object for those attributes...
I think it's great that you comment like this. It may seem like a small thing, but if more of these cumulate it makes the code (and the tutorial) harder to understand overall, I think.
Hope you'll enjoy the rest of the series!
Are comments still replied to on this video? I absolutely enjoy following along with this. I did run into an annoying snag with the controls being mixed up, however. When pressing either the left or right key, the element seems to move right no matter what. I threw in console.log statements on the left and right to make sure they aren't double called, but they seem to function fine. If the problem isn't in the controls, where could the error be?
Found the error within 0 seconds of posting this. Great video, can't wait to have a finished simulation on my hands.
Funny how many people find the problem right after writing the comment :-) There's also a discord linked on my channel banner. You can post questions and code there so I can have a look. I check it from time to time.
How can this video only have 320 likes?
I stopped asking things like that a while ago :-D
@@Raduyour epic, don’t stop the epic content
Hello! Than you very much for your help! I have a problem, my sensors just dont change color when they intersect with the boarders. I checked the code a few times, looked through all comments but didnt find anything the same, checked your code at the github, but cannot understand, what is the problem(( Thank you in advance!
Hi, do you mind sharing your code on my Discord (linked on my channel banner). I'll try to have a look.
hey nice video btw can you please cover the mathematics like the circle , angle , sin , cos etc im kinda confused + im bad at maths .
Hmm... good idea. I'll make a video about this someday.
But I try to explain it here, in words. So... the unit circle is a circle that has a radius of 1. We don't draw this circle anywhere. We just use it for calculating values. The full circle has 360 degrees or 2PI radians. The length of a circle is 2PI*R but since this one has R=1, the length is also 2PI. In a circle, sin^2(a)+cos^2(a)=1 for any angle 'a'. Cos is the x and sin is the y of the point on the circle that makes that angle 'a'. So, knowing any angle, you can get the x and value of the (so called) unit vector. A vector that has a length of 1 (the radius) and points at the given angle. If you multiply these x and y by some scaler (like 6) you will get a vector with a length of 6 (might be more useful because moving things by 1 pixel at each frame is quite slow). Hope this helps.
@@Radu thanks :D
Oh man this one thing threw me off. If we want a spread of 45deg then why are we dividing PI / 4 and not PI / 8 ? We wouldn't have to divide by 2 in the lerp function.
Edit: Ok my head isn't working. I assumed PI = 360 for some reason. Ehh.
But why is 0 deg pointing upwards in 3:50 ? Why the unit circle is rotated here ?
Edit some more: OK I went back to lecture 1 and I think I get it now.
Haha. Quite funny seeing your edits :-)
I read your first comment (without edits), but didn't have time to reply until now.
Yeah... the unit circle could have been explained better. Basically, car going upwards means angle zero for the car, and for the rays, straight ahead means zero. The sine and cosine are switched.
@@Radu Thanks. You truly care :*
@@QwertyNPC :-)
just asking what if you had one slightly longer range sensor that rotated constantly and once it notice an object it activates the other sensors so they didnt need to be on all the time?...i only ask if this is a good idea as i wanted to make a real life car(kids electric ride on car) so the computer would be small and not have a lot of computing power...do you think this way could help the program run better or by using all the sensor all the time would not lag the program?....these little cars are slow but the one im building has 36v hover board motors as i think you need proper high speed for the program to work properly....and yes i have a remote emergency off remote if anything goes wrong :)
I believe it would work. But if the 'rotating sensor' detects something, you should be able to know the angle and the distance away from the current location. Those are polar coordinates that you can convert to another format if needed, so you wouldn't need other kind of sensors really... it depends on the accuracy of this first sensor.
7:40
The sensor was not working for me after the save. So after LONG troubleshooting, adding "this.update()" to Sensor constructor helped me.
Interesting. This is the first time I hear this complaint.
It would be nice if I could have a look at your code somehow.
@@Radu
Hey Radu!
Greetings from Latvia!
First of all, great series. Just amazing!
So at 7:40 on my side, the issue was that ctx.moveTo(this.rays[i][0].x, this.rays[i][0].y); within Sensor > draw(ctx) was throwing 'undefined' error because this.sensor.update() was not called from car.js > update() and hence there was nothing in this.rays . So here fix was to add this.update() to Sensor's constructor.
But! The interesting part is that at the end, my code was not working again. And now the fix was ... removing this.update() from Sensor's constructor.
I am not good enough to explain all of this, but my guesses are - either I have something comepletly off somewhere (but I have rewatched some parts like 5x + checking against your GitHub) or maybe you cought your misplaced draw(ctx) in Sensor late enough that it was not an issue for your?
My code is at: github.com/CurtisLV/Neural_Network_Car_JS
@@karlism.5604 I suspect that you may have had an extra call to car.draw(ctx); above the animate function. It would try to draw the rays before the update. Many people have had a similar issue because, I think, I make that change too fast in the video and I don't draw attention to it. Your error sounds similar, but hard to say since you tried so many things :-) Anyway, let me know if you still have some issues, and happy to hear you like the course!
Radu, great video. I am working my way through the code and got caught on a : sensor.js:40 Uncaught TypeError: Cannot read properties of undefined (reading '0')
at Sensor.draw (sensor.js:40:29). I too added the this.update in the constructor of the sensor and it work fine. Did I miss something? Thanks again.
@@dukegard2504 I would say the same thing... You may have an extra car.draw(ctx); in main.js, somewhere above the animate function. If it's not that, can you send the code over so I can have a look?
You should actually remove those weights from your brain not your hands in the intro.... get it ... get it ... no no noooooooo
I see someone has my sense of humour :-D
but what's the joke here?
@@bravetreeapple1677 That is the point these isn't any. LOL
I got a bit of errors when I was writing your code escpecially when we draw the sensors
your code :
ctx.moveTo(
this.rays[i][0].x,
this.rays[i][0].y
);
ctx.lineTo(
end.x,
end.y
);
ctx.stroke();
I had to put in an if stateme if(this.rays[i]){} to check if rays[i[ exist before accessing it properties because if I dont I get
Uncaught TypeError: Cannot read properties of undefined (reading '0')
Just putting this out incase some gets the same problem
Hmmm, could it be that you still have a car.draw(ctx); in main, above the animate function? I removed it from there in the video, but did it quite fast and many people didn't notice.
Thank you so much for this insight. I was getting the same error, and apparently, it is quite an exceptional one, so you were the only one to even mention it!