How do I let cars drive on a street (AI)

0 favourites
  • 7 posts
From the Asset Store
Isometric Stategy Roleplay Game Building and Streets Pack.
  • Hi Guys,

    i'm just getting into path finding with construct 2 and I have logical question when build my AI for cars which should be able to drive through a city.

    See the picture attached (cars_street.JPG). I have some checkpoints (red rectangles) to find the path and move my car along to it. I used to tutorial https://www.scirra.com/tutorials/1118/page-1 to achieve this goal. The car is driving from one checkpoint to another (top corner then left corner etc.).

    This is quite a cool feature but I want more, but have no idea how to solve it with construct 2.

    • I want to let cars drive in a random way (not only from checkpoint 1 to checkpoint 2 to checkpoint 3 and so on). I want to let the cars find there own way: lets say on each cross-way the car changes its direction or if that is not possible just drive on the street to a random checkpoint.

    --> Let my car drive to random checkpoints is a little bit buggy because sometimes the car drives not on the street but on the road curb - how to let my cars drive ONLY on the street, which is shown on cars_street.JPG?

    • For performance reasons: just move cars which are in the layout and I'm able to see in my current resolution.

    Any tips on how to achieve my new goals?

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can randomize targets easily with System: Pick Path_Car where Path_Car.path = random(1, max_path)

    For choosing a path at a crossroad, if you have 3 directions, just choose(1,2,3) or similar (say, 1 left, 2 straight, 3 right). You could store in each Path_Car, its available destination Path_Car(s).

    Also rather than check for overlapping with Path_Car once the car arrives, I'd set it when you first choose the target (suggestion).

    For performance, C2 won't render what's not onscreen, and you can't pathfind to something offscreen anyway.

  • Hi codah,

    if I randomize my new target with random() [Pick Path_Car where Path_Car.path = random(1, max_path)] the car just stays at the current checkpoint and does not move forward. If i set it to 4 the car drives to this checkpoint. Also it seems that the car is ignoring my defined obstacles like it's shown in the picture attached.

    Thanks for your help!

  • I fixed random movement with the screenshot attached (using now Pick random instance) - movement is not very realistic.

    But the obstacle is ignored.

  • I fixed random movement with the screenshot attached (using now Pick random instance) - movement is not very realistic.

    But the obstacle is ignored.

    soo.. what's the current status?

  • Hi,

    everything works fine BUT the car is moving over the road curb (its Sprite2) to its checkpoint, although I have definied sprite2 as obstacle (I guess when I define somethin as obstacle then my car should NOT drive over it to drive to its checkpoint?)

    You can see this behaviour in the attached image.

    • Car drives to Checkpoint (Path_Car) (which is marked as "1" here)
    • Arrived at checkpoint 1 the new destination checkpoint 4 (marked with "4" in the image) is choosen and the car begins to drive over the road to the checkpoint
    • the blue line shows the movement of the car (the car ignores the defined obstacle?!) and drives over Sprite2
  • In the pathfinding tutorual, grab the piece of code under 'show grid' and trigger it in your code. This will show you where it thinks the obstacles are.

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