Linking 2 objects which are spawned at same time with a line

Hi guys, i would like to know how to make simple logic that can link every objects, which are spawned at the same time, using a line (or just a long plane with a line-texture). I made a simple illustration for that.

  1. 2 empties, these spawn 2 objects at same one same moment,
  2. the objects
  3. the objects are linked together with the string.
    when one of both objects disappear or both, the link will also be deleted
    thank you in advance

add a plane, edit it, move it over 2 units, scale it so its 1 unit long, and .001 units wide

now set its texture to a wire texture

now parent it to one of the objects

now use

import bge
cont = bge.logic.getCurrentController()
own = cont.owner
if ‘target’ not in own:
(tab)own[‘target’] = bge.logic.getCurrentScene().objects[‘Object2Name’]

own.alignAxisToVect(own[‘target’].worldPosition-own.worldPosition, 0 , 1)
own.localScale = (1,own.getDistanceTo(own['target]),1)

this should point the line at the target, and then scale to stretch it to the target

my phone is not allowing me to select more then one word at a time for some reason so I can add code tags, just remove the (tab) and add a tab,

hi BluePrintRandom,

should i parent the line to the object1 ? and make the logic bricks with the script to the line?

thanks BluePrintRandom, thats a nice tutorial !

Hm i would like to ask, how to make the line just link objects, that are spawn at the same moment?

spawn all the objects at the same time using another python script,

set the target at the same time

Line = bge.logic.getCurrentScene().addObject[‘Line’]

Line.worldPosition = object1.worldPosition

Line.setParent(object1,0,1)

Line.alignAxisToVect(object2.worlPosition-Line.worldPosition,0,1)

Line.localScale(1,Line.getDistanceTo(object2),0)

Line[‘target’]= object2