Police Quest 1 style driving

Started by Privateer Puddin', Mon 04/08/2008 00:26:57

Previous topic - Next topic

Privateer Puddin'

Hello, I am making an AGI style game and would very much like to have Police Quest 1 style driving. Most of it is no problem, until I get to other cars. I'm not entirely sure on the best way to do them. I would like them randomly moving about, while following certain rules, such as staying on the correct side of the road, stopping at lights etc.

I've tried in the past doing it myself (making 'routes' using character control module, just giving random coordinates in a loop and having no collision and so on) but would like this time to get something as close to PQ1 as possible.

Any suggestions or pointing me in the direction of a module or something that would help would be greatly appreciated.

olafmoriarty

A suggestion off the top of my head: Create as many seperate characters as you want there to be cars on the screen at all times. On start-up, put all the cars on the screen and start them up with a given direction and a given or random speed (see below), and write your code so that the cars move in the given direction as long as the game is not paused. If all your roads are horizontal and vertical, the cars will stay on the correct side of the road as long as you just move them in the same direction as the road goes, if your roads are diagonal I would suggest that you make the cars move towards a set point in the next cross or turn, and the cars should stay on the right side of road.

When the car comes to a roadcross (I'm assuming Regions can come in handy here), you make it run a function that first checks if the lights are red (and stop moving until they're green if they are) -- you have, of course, a variable somewhere you can check to see if the light is red or not -- and then selects a random direction to move from here. For specific crosses you could give specific commands (for instance, if you have an old tractor road or something going off the screen at one point, don't let 50 % of the cars passing it drive onto this road when in reality 2 % or so of them would do it).

Make sure that the cars at any time keep track of whether there are any other cars (including yours) nearby, so that they don't collide in each other or you from behind (this will especially be important if you want the cars to drive with somewhat different speeds, which could add a lot to the realism) -- make the cars slow down to don't collide with the cars in front of them. When a car leaves the screen, run a function that makes a new car (the same character, but since you can change all its properties including what it looks like, it's a new car to the player) enter the screen from a randomly picked exit (but check that there's no other car in that exact same position and choose another exit if there is) -- with a new look, eventually a new random speed, and so on.

Since the cars in this way always both sticks to safe parts of the road and they beware of other cars, you don't need to worry about them colliding with the sidewalk or each other; as long as you have a function that deals with what happens when they collide with YOU.

An additional suggestion: A quirky side effect for this is that there is a possibility for a car to drive around in circles on the screen for hours. A way of fixing this would be to add a variable that says how long a car has been on the screen, and if it has been driving around in circles for more than a given time (a couple of minutes), make it drive directly towards a given exit (still stopping at red lights) after this.

Coding something like this would probably involve a lot of work, but I don't think it would be terribly difficult.

Rocco

i planned to release the driving module i used in this game. -> http://www.adventuregamestudio.co.uk/yabb/index.php?topic=35278.0
but its only useable for the players car.
I used the CharacterControl Module for the other cars in the above mentioned game.
if my module is interesting for you, i'll intensify my cleanups on the module and release it in the next days.

magintz

What about lay out the maps to have three wlakable areads.

Red
Blue
Green

Red for the right side of the road
Blue for the left
Green for junctions (perhaps one for each junctions I don't know)

Then just move characters that obey set walkable areas, turning on and off the junctions for certain characters depending on their turn.

Just a quick thirty second thought, you might want to do it a better way or think about this yourself.
When I was a little kid we had a sand box. It was a quicksand box. I was an only child... eventually.

SMF spam blocked by CleanTalk