I was wondering if someone could explain to me how to make an object follow the motion of another object, but only along one axis. I know that the Steering actuator does a great job of basic following, but I couldn’t figure out if there was a way to restrict it to only follow the target object along a single axis.
import bge
def followOnX():
target = getOwner()
source = getObjectToFollow()
target.worldPosition.x = source.worldPosition.x
# This is just an example to read the source object from e.g. a trackToActuator
# You can retrieve the source object from wherever you want.
def getObjectToFollow():
try:
return getOwner()["_internal.source"]
except KeyError:
source = getActuatorObject()
getOwner()["_internal.source"] = source
return source
def getActuatorObject():
for actuator in bge.logic.getCurrentController().actuators:
try:
return actuator.object
except AttributeError:
pass
def getOwner():
bge.logic.getCurrentController().owner