Dear all:
I am part of a non-profit program for kids' safety. One of my pet projects is to bring a safe walking game to the program, based around real life scenarios. Enter Construct 2 and my willingness to learn a program I've never worked with before. That said, I've worked with simple code in Microsoft Train Simulator and PHP for Wordpress before, so the theories behind code principle and event hierarchy are not entirely foreign to me, and Construct 2's learning curve hasn't been too difficult up to now.
However, I've come to a bit of a standstill with AI control; hence, before I try to go any further with the game project, I thought I'd ask if my goals are even remotely possible.
At present, the game places a player (with 8-position control) on the sidewalk on a top-down map, with single-lane streets and bike lanes in either direction. The street, bike lane, and sidewalk are all individual objects. Each crosswalk signal has two animations (walk/don't walk, alternating between each direction), and each traffic signal has three (green/yellow/red), and the animations are timed together so that the automobile traffic light is red when the crosswalk is safe to cross. The walker/player is at the left, on the sidewalk:
The green lines are solids, there to assist me when trying pathfinding experiments.
The behaviors applied to each BlueCar sprite are: Solid / Car / LineOfSight. I also have max/minimum speeds listed as instance variables.
The above is the rough map of where I've been able to get after a few days of fiddling with the program, but I've been having nothing but problems trying to work out AI.
Following is my laundry list of questions, which I sincerely hope can be answered before I spend ages trying to attempt something that may be impossible - and before I tell my administrators to buy the full version of Construct 2:
- Pathfinding isn't working for me. I've experimented by placing solid lines against the edge of the road terminating at the intersection, but when I can get a car to move to an X,Y coordinate, it'd rather bump up against the solid line all the way to the intersection rather than avoid it.
- Is there a function to turn on the visualization of cell obstacles, as shown in the Pathfinding tutorial? I can't find it. I'm suspecting that there are not enough cell obstacles surrounding the car to make it reliable, but I can't verify that without being able to see the buffer zone.
- I've tried copying Pode's brilliant CarAI.capx with targets within waypoints. In doing so, I was able to get a car to travel down a street in a straight line, and make a right turn. However, I'm not really sure if its possible (with this method) to randomize (or alternate) whether a car turns left, right, or continues straight ahead. I tried using animations to change the state of each target, but I probably borked up the conditionals. Should I continue trying this?
- Million dollar question: Is it possible to randomize whether a car continues ANY path reliably with ANY method mentioned above?
- Two million dollar question: If any of the above is actually possible, can a code be written to stop cars at an intersection stop line sprite, such as the one below...
...when the traffic light for that direction is red? I know I can tie in an event to the animation frame of the red traffic signal, but - so far - I have not been able to figure out how to write a conditional stating code to the effect of "BlueCar speed = 0 only if touching the stop line sprite when trafficsignal001horizontal animation frame = 1" though I'd assume this is how it would be done (am I completely off track here?)
- Any automatically generated cars (e.g.: System, Every 5 Seconds | Create object BlueCar on Layer 3 at (X,Y)) ignore any and all events before them. Besides being a pain, it has limited the scope of my experiments. I think I read something about automated system events not taking on prior events before them, but I never did find an obvious solution for this in the forums (though I seem to remember a thread about using the "System: On every tick" event to solve it). What have I missed?
- Because of this limitation with the auto-generated cars, I can't get any automated car to adhere to line-of-sight rules. Thus, I'll get a big pileup of cars smashing and pushing behind the one car generated on the layout - provided that layout-based sprite stops.
- This also brings up another thought: I don't mind making the cyclists follow straight paths exclusively; thus, I can generate them traveling in fixed directions from their spawn point. That's easy enough, and whatever code can stop the cars at the intersection can also stop cyclists. Thing is: Can I apply line-of-sight to an auto-generated object (the cars) to stop them in the middle of left and right turns on green to allow a cyclist to travel straight through the intersection?
- I'd like to have about 8 or 9 intersections in this map before I'm done, allowing a player to travel from "home" to "school," along with a semi-city/neighborhood environment between the two. Thus, ANY of the code mentioned above reliable and simple enough (relatively speaking) that it can be coded to work with said nine intersections.
- I'd like to spawn the cars off map, but - near as I can figure it - I can't do that if the car also has the Destroy Outside Layout behavior enabled as well, correct?
- Bonus points if the cars can be made to pull into and out of parking lots and spaces. Yes, I know I'm asking too much.
Let me know if I'm way off track, or whether there is hope for this project yet.
-Kurt