Zachary_Alan
Member
Hello, I completed the traffic spawning system in my GTA 2 style game, and it worked, but after a bit it stopped. The way it works is it checks the player distance, and then creates a car, and then a pedestrian in the car to drive it. Problem is, the pedestrian only spawns about 20% of the time, and I don't see any pattern to when it works and when it doesn't (The spawning system is an object that I place everywhere I want a car to spawn. Parked cars without peds in them are not supposed to exist).
The despawn distance for the peds and the cars are the same. I do have pedestrian spawners, that spawn people walking down sidewalks, but those aren't connected to the traffic spawners in any way. I've had a few instances of code that looked okay not working as it should.
Code:
///Traffic Spawning System Core
distance = distance_to_object(obj_player);
///Spawn
if( distance < 445 and distance > 405 and !collision_circle( x , y , 140 , obj_car , false , true ) and instance_number(obj_car) < 20 ){
instance_create( x , y , obj_car);
instance_create( x , y , obj_ped);
}