Make object stay between 2 others

I would just like to know a way for an object to stay between 2 others.

I think python would have to be involved.

Maybe something like,

get game logic
get object list
cube = "OBcube"
cube001 = "OBcube.001" 
middle = "OBmiddle"
cubeposi = cube.Xposition
cube001posi = cube001.Xposition
middleposition = set.position (cubeposi + cube.001posi / 2)

now if you can’t already tell, I don’t know much about python.

If someone could help me out here, that would be muchly appreciated.


A – B – C

import GameLogic
objList = GameLogic.getCurrentScene().getObjectList()
posA = objList["OBCubeA"].getPosition()
posC = objList["OBCubeC"].getPosition()

objList["OBCubeB"].setPosition((posA[0]-posC[0])/2, (posA[1]-posC[1])/2, (posA[2]-posC[2])/2)

Good ol’ midpoint formula.

import GameLogic as g
cont = g.getCurrentController()
own = cont.getOwner()

list = g.getCurrentScene().getObjectList()

ob1pos = list["OBobject1"].getPosition()
ob2pos = list["OBobject2"].getPosition()

middlePos = [(ob1pos[0]+ob2pos[0])/2,(ob1pos[1]+ob2pos[1])/2,(ob1pos[2]+ob2pos[2])/2]


EDIT: J09 beat me :[

i think J09 is wrong with the minus signs but bacon got it right?

alright! Thanks guys!