-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|82|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Blogs Home -> Blogs


 
Pakz
Created : 20 May 2022
Edited : 20 May 2022

Racing bot in jse



I have been tinkering away at a racing game. This only to learn about how to go about creating such a thing.

I made a couple of versions and ended up looking at the 'nature of code' book. Here there are some tips and tricks that I also remember reading in too complex game ai books.

Maybe I wil try and tackle some boids techniques and try to put multiple bots on the track. Also I keep thinking at things like slowing down near corners and speeding up. Collision slow down when near the edge(radius) of a track(line)


  --v

 

Comments


Friday, 20 May 2022, 07:00
Jayenkai
You know you're supposed to put your name in the bit where it says <Your Name Here!>, right?!



That's working pretty nicely.
Currently it looks a little "bumpy" when the red and blue spots jump from point to point, but once they're invisible the remaining car will look a lot smoother in its driving.
Add a bit of physics into the mix, so the car slows down at sharp corners and the like, and you should be golden, really.

If you can look up the next three points, you'll be able to tell if there's a turn or not, and then slow down whenever that's happening.

Like you say, though, I'm not sure that JSE can handle more than a couple of cars doing lookups like that. I'm sure there's a better way, but.. yeah, this is more or less how I did it in my Really Retro Racing thing!
Friday, 20 May 2022, 07:07
Pakz
I think the distance function can be used to find the end of a line. This is where a new line begins. I think I can do that easily. Turn speed can maybe then also use some experimentation.

I had sped up the bot so the helper graphics got a bit jurky.

Maybe you can add a user name in jse? Where it auto puts in the name into a new project? But this would probably get removed when the browser cleans it cache
Friday, 20 May 2022, 07:18
Jayenkai
I've opted against "logging in" at all in GotoJSE.
If I DID do logging in, I'd have to fart about doing registrations and logins and whatnot. Socoder's login is messy enough

For my turn speed, I looked up the next three points. Work out the angle of a->b and then b->c, and the Abs(difference) should be roughly how sharp the upcoming turn is. Then you can set a top speed for different angles, and reduce the car's speed to match.
Be sure to use acceleration and speed, as opposed to just dropping the speed, or it'll look a bit "cheaty"!
Friday, 20 May 2022, 07:44
Pakz
I might investigate first on how to do a supercars(amiga) tile set and sprites and implement scrolling. I stil remember someone many years ago making a quick supercars mockup in Delphi. This I want to do myself one day too.
Saturday, 21 May 2022, 03:38
AndyH
That looks really cool. I love super cars although replaying today the collision detection with the track edges is annoying.

Please, make a super cars game 🙂
Saturday, 21 May 2022, 03:51
Pakz
I was just about to continue on recreating a series of the track tiles. There are not that much screenshots around on the internet. I think I am using Supercars 2 screenshots right now. Supercars 1 looks a bit simpler.

This is what I got right now. A car driving on a bare non tiled procedural road. I have been thinking on how I could do procedural level generation.


  --v

Saturday, 21 May 2022, 04:20
Dan
You know you're supposed to put your name in the bit where it says <Your Name Here!>, right?!


How about if you let the user enter the name, which would be saved on/in the local storage, which would fill in when a new project is created?

That would be the win/win situation, no need for log in, and the name would not needed to be typed every time a new project is started.
Saturday, 21 May 2022, 05:27
Jayenkai
Sorry, I know how hard it must be to type your own name in, after all of that typing in of the rest of the entire thing you've written.
Saturday, 21 May 2022, 11:31
Dan
Oh, "Dan" is only 3 letters, so that's easy.
but look at: Pakz001(Rudy van Etten)

I do not mind. The idea is, because it is a repetitive task, it could be done by the system.
Saturday, 21 May 2022, 12:25
Pakz
I grabbed my old Trust bluetooth keyboard. It stil works. It even has cursor keys. Which is useful with typing.
I had a go at working on the tiles. Another 12 are done. I'm 1/4th filled up with the amount of symbols. I think I wil just go with a grass theme and no water. There should be enough space for some plants and grass variations.

I wil keep an eye on the author name field. And identing the code too.
Friday, 27 May 2022, 06:54
Pakz
I did a bit more today. The next.. bug kind of set me back for an hour or so. But I was able to get multiple cars and scrolling working.

Edit: the racing tracks can be placed anywhere. They eventually wil be placed on top of the tilemap. The supercars tiles are not in this project, but in a different version file on my github.

  --v

Wednesday, 01 June 2022, 12:51
Pakz
Wow. I had some buggy large group of cars doing the weirdest stuff. Today I was working on adding 'turbo' and some personality per car. Overtaking logic and such.
When putting it together it was rather buggy. I started watching some races and tried to add one line. That was making sure that breaking near the end of another car worked as it should. This seemed to lead to the current result.

I might continue on the tiles now and start to figure out how to do a supercars like track generator.

Warning. Messy hack code.
  --v

Friday, 03 June 2022, 14:00
Pakz
Ok. I think I got the most racing bug fixed. This was where cars would rotate into each other. Sometimes though a car can drive through another car. More analysis needed.

I checked the optimizations. Fixed some code that I forgot to optimize. The speed of the cpu needs to be incredibly good though. At the moment I can have 16 cars on my m1 ipad. The start of a race it dips the fps. But it goes to 60 when the cars are spread out.(local area collision) My 2017 laptop can only have 2 cars racing at full fps. Same with my 2017 ipad.

Maybe I will add more intelligence as there is a lot of bumping.

  --v