redstone-like pipe simulations in bge

I am trying to set up a pipe system in my game that works kind of like redstone wiring in minecraft. when I activate one pipe I want all of the pipes following it to activate in sequence (this will be signified in the final game by filling each pipe with liquid)

Right now I have it set up so that if a pipe is active, then it sends a message to the next pipe to turn on. I am using a ping-pong action to fill/empty each of the pipes.

My problem is that when I activate the first pipe, the rest of the pipes following it flash on and off instead of holding their state.

As a side note, right now I have to manually tell the pipes what order to send the message in, but I would like to implement some sort of automated setup with python where pipes can detect if there is another pipe in front of or behind them, and send the on signal to the corresponding object.

thanks in advance for the help! :yes:

The best way to do it automatically would be to use Ray sensors and Python, this way you can do it automatically by using the hitObject property which will return the object the ray sensor is sensing, if there is one.

So you might have (minimal example assuming a straight line of wire objects and assuming that is being run on all of the objects, objects with a boolean property named ‘On’ and two ray sensors)


import bge

con = bge.logic.getCurrentController()
own = con.owner

rayForward = con.sensors['FrontRay']
rayBack = con.sensors['BackRay']

rayObjectFront = rayForward.hitObject
rayObjectBack = rayBack.hitObject

if rayForward.positive == True and rayBack.positive == True:
    if not rayObjectFront == None:
        rayObjectFront['On'] = True

if rayBack.positive == False:
    if not rayObjectBack == None:
        rayObjectFront['On'] = False

I suggest to project the structure of the pipes (and their relationship) onto an internal model which allows ease such processing.

E.g. a graph.

  • the pipes are nodes
  • the connected holes are the edges
    or the other way around.

Indeed to you translate the scene model (3D models) into the internal model (graph) with the method Ace Dragon describes. It allows you to find the relationship between the pipes.