How do I do to make the AI CARS stop at sprite image points?

0 favourites
  • 9 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • Hello! How are you? After sucessfully create random vehicles on street of my test city, i would like to make them to stop on some image points of my intersection for some seconds, but this is not working. I really not good with expressions, but i was trying to guess what to write to make it work properly. Please, take a look on my images below:

    PS: (In the IMG Nº1, each of the 4 ''Parameters for ''inter'' codes, there's a different number for the ''inter'' imagepointX and Y.)

    1-

    2-

    Question 1: As my codes are not right, what should i do to make it work?

    Question 2: How can i make the cars that come from behind to stop and avoid hitting the car in front? Because i tried a lot of codes using ''Line of sight behaviour'', but they still hitting the others AI cars on intersections and etc.. The L.O.S behaviour only works if i set them stop when they has the player on his line of sight.

    Thank you in advance!

  • For your first question there are several solutions.

    1. If you just want your car to pause before entering the intersection and don't care where it comes from, you can change your "inter" collision polygon to something like this (example for intersection with 3 exits):

    Then just check your car for collision or overlapping and pause it.

    2. If you need to know which side of the intersection the car is on, you can make a very small collision polygon in the center of your intersection, define image points on each exit and use "Overlapping at offset" event, offsetting your collision polygon to image point position. (This is what you were trying to do)

    3. You can simply create a small invisible sprite and place it on each side of your intersection and check collision with that sprite.

    I made a demo of 1 and 2, have a look:

    https://www.dropbox.com/s/mxhj99oz68mwv ... .capx?dl=0

  • atmas why use overlapping points for a pretty intensive graphic game? i would've used "distance again" (i know dop2000 ) because its less heavy on systems logic. using overlapping points of images the computer or system has to measure each pixel in each frame and see if they are colliding. you could use bbox left right top bottom of the car and target imagepoint.x,y and measure the distance if distance is a surtain safety number car stops. you will notice with this approach a 50% to 90% cpu usage drop, depending on your project how heavy is from graphic point of view.

  • atmas why use overlapping points for a pretty intensive graphic game? i would've used "distance again" (i know dop2000 ) because its less heavy on systems logic. using overlapping points of images the computer or system has to measure each pixel in each frame and see if they are colliding. you could use bbox left right top bottom of the car and target imagepoint.x,y and measure the distance if distance is a surtain safety number car stops. you will notice with this approach a 50% to 90% cpu usage drop, depending on your project how heavy is from graphic point of view.

    Hello, how are you? I simplified this problem by creating some stop signs before the intersection, so the AI car now stops on the line for some time and then, he start moving again. Could you help me with another issue please? It's

    the following: AI cars that are on the same layer, won't detect each other. I tried to use the L.O.S behaviour, so each AI car would know each other and would avoid crashing one into another, but this won't work. I'm saying that because when i use the L.O.S behaviour in the AI cars to detect the player that is in another layer above, it works 100%. What can i do to fix this? Thank you man!!!

  • I tried to use the L.O.S behaviour, so each AI car would know each other and would avoid crashing one into another, but this won't work. I'm saying that because when i use the L.O.S behaviour in the AI cars to detect the player that is in another layer above, it works 100%. What can i do to fix this? Thank you man!!!

    L.O.S is line of sight which basically uses some sort of distance(x1,y1,x2,y2) but most of times it breaks when used with pathfinder together, so my advice would be to drop L.O.S and use the expression " if distance(car.x,car.y,car.x,car.y) less or equal then 100 car stop (at this point you made your own L.O.S without the behavior and without the problems of L.O.S and Pathfinding behaviors). now i know it might seem obfuscating from our point of reading the code, but C2 actually has a background system that when you appoint the car.x, same time, basically what does, for each car that detects another instance of the same car object it applies that. you might need to add for each loop while using it. but should work, i used it on a aquarium type of game and AI ( AI used same name no numbers picking or other tricks just pure "aifish" for all different types of fishes.)worked awesome they were hunting each other and the player no confusion whatsoever in code. so that being said, i think it might work for you also. Hope you can understand my spaghetti code from above and the explanation.

    Edited: ehm.... i forgot i did used a identifier i used their frames numbers. but i dont think that would help in your case let me check something il get back to you.

    Edited 2: so i made this capx its not working perfect, but LOS seems to do the job pretty good here, i think the old bug is not a problem anymore, however distance it seems here is a bit frustrating to work with i can crack this when my head's clear. 11:36 pm here been up for all day, the thing with AI in general you have to code each side of car and and make it aware of its surroundings even if the cars are the same object basically, it's IID or UID picking but i can't find the expression sign for not equal so i can add it in it's some weird C2 advanced expression(not the not equal in the normal dropdown). il post in morning more for sure. i really want to fix this one, bugs my brain if not. if you're in a hurry you could try AI cars he has a template that has AI s racing each other and their avoiding each other however is a very complex system he has there with a lot of custom plugins if im not mistaken. (at Rex sorry for summoning you.)

  • > I tried to use the L.O.S behaviour, so each AI car would know each other and would avoid crashing one into another, but this won't work. I'm saying that because when i use the L.O.S behaviour in the AI cars to detect the player that is in another layer above, it works 100%. What can i do to fix this? Thank you man!!!

    >

    L.O.S is line of sight which basically uses some sort of distance(x1,y1,x2,y2) but most of times it breaks when used with pathfinder together, so my advice would be to drop L.O.S and use the expression " if distance(car.x,car.y,car.x,car.y) less or equal then 100 car stop (at this point you made your own L.O.S without the behavior and without the problems of L.O.S and Pathfinding behaviors). now i know it might seem obfuscating from our point of reading the code, but C2 actually has a background system that when you appoint the car.x, same time, basically what does, for each car that detects another instance of the same car object it applies that. you might need to add for each loop while using it. but should work, i used it on a aquarium type of game and AI ( AI used same name no numbers picking or other tricks just pure "aifish" for all different types of fishes.)worked awesome they were hunting each other and the player no confusion whatsoever in code. so that being said, i think it might work for you also. Hope you can understand my spaghetti code from above and the explanation.

    Edited: ehm.... i forgot i did used a identifier i used their frames numbers. but i dont think that would help in your case let me check something il get back to you.

    Hey man, thanks for your attention! A lot of people are helping me, and for me, it's very important, because i'm learning all the codes by myself and almost getting nut because of some little issues hahaha. I understood 100% of your explanation! I'll try it now. I was trying some combinations hours ago to find the right way to write that same code you told me. I was trying to use the ''SYSTEM> COMPARE TWO VALUES'', but with wrong logic. If it work for me, i'll reply here. Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • atmas here is version 2 with the expression i was talking about the manual alternative to notequal is "<>" so its kinda of working however there's plenty inside there that i hope you will understand i didn't spent any time to comment it. if you need that let me know. dont mind the LOS behavior is still attached but not used, i only used pathfinder to make the objects move towards some direction and some extra identifiers with their own identifiers as instance variables, there is a 40 pixel jump backwards when they see the collision which makes them get out the field of view and then reenables the points hope you can adapt any of this to your project and possible solves your problem. .... even this since is not perfected and done in a rush still fails some times.

    the extra red dot might not be needed, and you could actually pick the same AI using distance by comparing " <>" UIDS of objects. that i will definetly do in morning. Good night!

    Edited: the "<>" is a operator not expression but hope it made sense.

  • atmas here is version 2 with the expression i was talking about the manual alternative to notequal is "<>" so its kinda of working however there's plenty inside there that i hope you will understand i didn't spent any time to comment it. if you need that let me know. dont mind the LOS behavior is still attached but not used, i only used pathfinder to make the objects move towards some direction and some extra identifiers with their own identifiers as instance variables, there is a 40 pixel jump backwards when they see the collision which makes them get out the field of view and then reenables the points hope you can adapt any of this to your project and possible solves your problem. .... even this since is not perfected and done in a rush still fails some times.

    the extra red dot might not be needed, and you could actually pick the same AI using distance by comparing " <>" UIDS of objects. that i will definetly do in morning. Good night!

    Hi gamescorpstudio, i'm trying to solve this problem out since morning here.

    I'm sure your example i'll help me a lot! Thanks again man and have a good night!

  • i would've used "distance again" (i know dop2000 )

    Yeah, I would've probably used some calculations too instead of overlapping checks, if this was my game and I had more time to spend on it. Collision polygons offer a quick and "dirty" solution which could be sufficient on early stages of game development.

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