UPBGE Traffic System v0.2

Hi all,

After 5 years I have an update:

I’m working again at the Traffic System v0.2.

This thime in UPBGE 3.0.

At the moment I have

  1. addon for building roads plus the auxiliary of assets placing
  2. addon to generate NPCs based on the checkpoint selection (circular path)

As reference I’m using The City of Lost Heaven/Mafia 1 game.

Old version:

Does it follow traffic lights? If not, I can make one that does if you give me this one;)

Eventually it will have traffic lights, I have all the logic for light system.

I will share the .blend at one point, if there is any interest in developing this.

What I would like to do next is:

  1. making it more stable easier to add new cars
  2. building a global script for the waypoints following system (I would need help on the scripting part).
  3. creating an addon where you can allocate the car and define the waypoints (using a text file or and xml).

The addon part sounds harder. And in your case it’d be rather useful to make a GUI version of it which allows player to add object to car list and that way generate it’s stats(properties marking speed, target count etc.) and, of course, place in hidden layer. Make car choose random target would be nice(using random props). And add-on may also contain target adder - just click on add target and it will make the target(just like adding any object in blender) in center. Maybe each car can choose as target any object with property “carTarget” on it or something like that? Yeah, add-on would be very hard to make.

So, my idea:
*Player make his car mesh and bounds(it can be just a cube or he can parent thousands of stuff to car, make it use constraints etc. Main is that it has one owner who holds all the car stuff in one car).
*Player place it in inactive layer.
*Player ensures that car holder(the actual car) is selected and than in add-on GUI click on “Generate Traffic Car”
*Car gets a lot of properties(speed, turnSpeed, obidience(boolean - if true, it will use traffic lights and break when other cars close, else it will just drive and ignore others and traffic lights), navmesh(bool - if true = use navmesh(another property “navmeshName”(string) that allows user to input the navmesh name), if false = use raycasted calculations or whatever that he avoids crashing walls).
*There is a button on the left that allows you to add targets.
*For each target you can select which type of cars(which car in inactive layer) can use it, maybe it should contain a string propery. This may be more complicated.
*You can click on the left “Generate Traffic Light”

May be complicated, but should be worth of try :wink:

I would love to use something like this in videogame.

You know I’m interested cause my city generator needs a traffic system too but for terrain I need a new dynamic way of texturing all tiles as one. Either cube projection unwrap UV for all tiles as one or like, projected from a lamp bump mapping or cube mapping, not per UV of individual object but per layer or group of objects.

When can we see/test a blend file ?

If the traffic system is going to overload the CPU I will have to remove all the buildings, terrain and everything else.

Usually traffic system is not problem. Yeah - for me almost none of CPU tasks are not problem if games has a lot of graphic(polys, shaders, resolution, render tu texture) because of high GPU latency!

Hi,

I would like first to give some credit: ThaTimst3r for the logic and Blender3DMaster for the cars script.

Maybe someone can help me with a python code I would like a cube to track to 3 spheres named T1, T2 and T3 and to be able to add any other sphere like C1 any were between the T ones, please see attachment.


If you use steering, my script:


import bge
from bge import logic
import random


#get controller
cont = logic.getCurrentController()
own = cont.owner
sens = cont.sensors
act = cont.actuators
#get scene and object list
scene = logic.getCurrentScene()
objects = scene.objects
#create and generate target list
targets = []
for obj in objects:
    if "target" in obj:
        targets.append(obj)
#calculate current target
reachTarget = sens["reachTarget"]
if reachTarget.positive:
    targetId = random.choice(targets)
    while targetId == own["TheTar"]:
        targetId = random.choice(targets)
    
#get drive act
drive = act["drive"]
#set drive
drive.acceleration = own["acceleration"]
drive.velocity = own["maxSpeed"]
drive.turnspeed = own["turn"]
drive.target = targets[own["TheTar"]]
#drive
cont.activate(drive)

may be useful. If you can understand it, try to modify it! :wink:
Any target sphere requires property ‘target’
Car requires following logic bricks:

collision sensor(tap/property ‘target’)… will continuew this, have to go! :frowning:

Thanks adriansnetlis but this doesn’t answer my question.

What would like to accomplish by doing this?Please tell us.

T1, T2, T3 plus C1 are points that the cube has to track in a loop.

I’ve needed a system like this for a project I’m working on. I will keep you in mind. :wink:

Track to nearest property script would help with that.

Hi all,

I’ve developed this patrol system that I’ll be using for the traffic system.

Typically you “simply” add the new item to the collection of the existing items. As you use hard coded items this is impossible for you.

Here are some hints:

  • when you have more than one object that serves the same purpose (e.g. acting as waypoint) it is a good idea to place them in a container e.g. a list. A list is good when you want to establish a specific order.

   objects = scene.objects
   wayPoints = [objects["one"], objects["two"], objects["three"]
   setWayPoints(wayPoints)

def setWayPoints(wayPoints):
    return getOwner().get("current waypoint")

def getOwner():
    return bge.logic.getCurrentController().owner

  • you implement a single operation once for a single element. Then you can take any element from your container and perform the operation on it.

    determineNextWayPoint()
    wayPoint = getCurrentWayPoint()

def determineNextWayPoint():
    currentWaypoint = getCurrentWayPoint()
    wayPoints = getWayPoints()
    index = wayPoints.index(currentWayPoint)
    nextIndex = (index + 1) % len(wayPoints) # wrapping
    nextWayPoint = wayPoints[nextIndex]
    setCurrentWayPoint(nextWayPoint )
    
def getCurrentWayPoint():
    return getOwner().get("current waypoint")

def setCurrentWayPoint(wayPoint):
    getOwner()["current waypoint"]=wayPoint

def getWaypoints():
    return getOwner().get("waypoints")


Everything untested - errors inclusive

BTW. if you call something “Boolean” then do not fill it with wine.
own[“Boolean”] = 2 should make your toenails furl. A boolean is either True or False and NOTHING else.

Thanks Monster!:yes:

Hi all,

After 5 years I have an update:

I’m working again at the Traffic System v0.2.

This thime in UPBGE 3.0.

At the moment I have

  1. addon for building roads plus the auxiliary of assets placing
  2. addon to generate NPCs based on the checkpoint selection (circular path)
4 Likes

very good, I have also developped an path finding system with checkpoints in my game.

Are your npc’s wearing a mask ? Also, do they just go randomly to a nearby checkpoints or are they searching a shortest path to a destination ?

1 Like