Creating top-down car traffic (AI)

0 favourites
  • 13 posts
From the Asset Store
Set of tiles to create a map for top-down games with island theme
  • Hello!

    I was wondering if it's possible to make some simple car traffic.

    Now I *think* I grasp the basics of it, but I strongly feel like it can be done in a much better and less time consuming way.

    So basically, I have 18 different cars (most same models but different color) and I want them to stop and give way when a car is coming from the right.

    What I have now is like this:

    As you can see that can be much more efficient, I would have to copy that group and change it 17 times for each car group.

    I was also wondering how to handle things when four cars are arriving at the crossing around the same time, with LOS they might just end up giving way forever to the one on the right. Now I did have some stop lines added all over the map, basically the horizontal lanes are supposed to be given way. Green and grey car are supposed to give way as you can see so that might solve the problem a bit, but I don't understand yet how to efficiently code that?

    Also I notice that with LOS the cars only stop when they are (almost) hitting the other car, regardless of how much LOS sight I give them. This happens when the car from the bottom has to give way to a car from the left for example.

    So I thought about using families. But I couldn't figure out how to get the one that has line of sight with a car, to get that specific car to stop instead of the whole family. If any could shed any light on this traffic issue.. I'd be really grateful.

    P.S. Here's a .capx sample of the situation: http://mediaconceptfactory.com/images/Traffic.capx

    • R
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi

    I give it a quick go to try and this is my results, I'm not sure if this is what you looking for and I'm sure is not the best but it might help you to give some ideas.

    Note I didn't have much time to test it as I done it quick, so test it properly because you may find some bugs if you need help let me know I will have a look.

    you can customize it a lot more and improve it if you know how.

    (The Middle roads = Horizontal) cars have a preference which is the Right like you asked

    For fast Driving and Animation Change Variety >>>>>>>activate the group >>Extras

    Capx: https://www.dropbox.com/s/sgrr2of0okr2s9e/GTA%20San%20Andreas%20Light%20%29.capx?dl=0

  • Thanks, I will take a look as soon as I got some other issues solved for another game!!

  • Hey tarek2, thanks so much! That traffic is actually pretty darn well done. The only thing left to improve could be to stop the cars from driving in 'pairs' since at one time, they'll end up waiting for eachother when giving way and they drive in pairs forever. Probably the issue is the wrap behavior, because it causes the two cars (pair) to continue as they were after having to give way.

    Did you originally create this capx one time for yourself?

    It might take some time for me to figure out how it's all done though, lol, I guess I'm still a beginner.

    Anyway, thanks again!!

  • Here's and old capx experiment of mine that may give some ideas.

    https://www.dropbox.com/s/df8jtstjva45m ... .capx?dl=1

    The cars don't really follow any traffic laws, they just go while trying to not overlap each other. It can fail when multiple cars enter an intersection at the same time, so some right of way is needed. The hack fix was to make the stop temporary and they'll eventually just drive over each other to keep things going.

  • Thank you, sir, I'm glad you like it

    yea I created from scratch I didn't have much time to do it that's why I did it pretty basic so you can follow easily how it was done and from there improve it on the top of it with your ideas, I didn't want to make it to complicated other ways you will find hard to follow it. I tried to simplify it as much as I can.

    is true I had the problem with driving in pairs and to avoid that I came up with the idea with the Speed boost but you have to activate the group "Extras Only " did you try that? it is not active by default, it improves the driving on pairs a little bit not much, but much better than when they are all driving at the exact speed. I tried many different things to avoid the driving on pairs but the problem I saw at the end is that are many stops in very short roads and doesn't matter how I put one car faster and the other slower they will catch up again in the stops because the faster one comes back from behind and has to wait and drive at the same speed of the slower one that's in front of him blocking him.

    I will give it another go when I have time and will see how can it be improved, does the map has to be exactly that way or can it be changed?? what is your goal for this game ?? the more info you can give me the better to take it into account for the logic, you need it slow or fast driving game?

  • No problem.

    You are very helpful. No I forgot to activate the 'extras' group, haha. The idea I had for this game was to play as a police car arresting bad guys. You'd have to drive through the traffic, avoiding cars and pedestrians while being in time to catch the criminals.

    To be honest with you though, I left the project/idea for what it was as it took some time before someone came with a solution for the traffic + I once again had a too large project scope! I always have loads of ideas that I want to implement and the scope of the game becomes too big. I pretty much finished the map, and a handful of cars and the pedestrians (all top down).

    Looking at the code from your example it might take some time for me to understand it all. I do want to get better at programming but I think I'll need to start making games that are less complicated and go from there.

    Oh yeah, I also had issues with the car movement (for the player controlled car) I just couldn't figure out how to program it so it would steer normally at higher speeds and it the car would always drive really fast backwards, simulating car behavior is tricky. So yeah lots of reasons for me to start with something else, something smaller.

  • Nice one R0J0hound

    Runs really smooth

    Cool

  • Here's and old capx experiment of mine that may give some ideas.

    https://www.dropbox.com/s/df8jtstjva45m ... .capx?dl=1

    The cars don't really follow any traffic laws, they just go while trying to not overlap each other. It can fail when multiple cars enter an intersection at the same time, so some right of way is needed. The hack fix was to make the stop temporary and they'll eventually just drive over each other to keep things going.

    Hey R0J0hound! I really don't know how to thank you buddy! Let me ask you one more questions please: How dospawn vehicles only near the player, but the condition is: The player won't see the cars spawning? And about the PED'S, can i do the same thing to pedestrians? I'm creating a game like gta 1, and i been searching for things like that for 8 months! Do you have any more .capx related to this? And if not, where can i find it please? I already searched all over the internet. Thank you!

  • atmas

    In the capx it just creates the roads. at the start of the layout. You could just do what you said and only pick the roads off screen and within a certain distance of the player to create cars on.

    Pedestrians could probably be done in the same way, although you probably could ignore the collision detection. Here's another idea along those lines:

  • atmas

    In the capx it just creates the roads. at the start of the layout. You could just do what you said and only pick the roads off screen and within a certain distance of the player to create cars on.

    Pedestrians could probably be done in the same way, although you probably could ignore the collision detection. Here's another idea along those lines:

    Hello! R0J0hound! As i said before, i downloaded your .capx road2, and then, i tried to write the same codes you did and now it's working very well! I'm not good with math, but now i guess i will be able to keep creating my game. The only thing i have is creativity. You don't know how much you're helping me now. I created 30/ 40 vehicles, an inventory system, some fake 3d buildings months ago. And this and the .capx city walk, were the things i been searching all over the internet. that i never found before. Thank you so much once again!

  • Hi, i know its an Old topic but have someone still this gta sa light capx? I was searching SO long but theres everywhere deleted files :/

  • Hi, i know its an Old topic but have someone still this gta sa light capx? I was searching SO long but theres everywhere deleted files :/

    Hi

    I had to delete a lot of stuff as I didn't have space on DropBox, here is a new Link

    https://www.dropbox.com/s/q85131zqzjgkksz/gta%20san%20andreas%20light%20%29.capx?dl=0

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)