Hi, I’m trying to get a 2d-like object on an overlay scene to follow a moving object on a main scene. Logic bricks only give me the option of sending it a message. I don’t think I can do a parent across two different scenes.
I thought that if I used Python, I might be able to get the 2d object to follow the object on the other scene by using something like:
from bge import logic
<b> Note: The following line is NOT an actual blender function</b>
otherscene = logic.getAnotherScene('Scene')
scene = logic.getCurrentScene()
2dob = scene.objects['2dobject']
3dob = otherscene.objects['3dobject']
3dpos = 3dob.worldPosition
<b> The following line probably needs tweaking.</b>
2dob.worldPosition = [3dpos, 3dpos, 0]
Thanks
Edit:
Tried:
from bge import logic
as = logic.getSceneList()
cs = logic.getCurrentScene()
os = as.Scene
thpos = cs.objects['2dobject']
ppos = os.objects['3dobject']
thpos.worldPosition = ppos.worldPosition
‘as’, as you have defined it, is a list returned by the ‘getSceneList’ function of the logic module. The list consists of scene objects - it should be something like:
[GameScene, GUIScene]
The last added scene should be the GUI scene, since the first would be the game scene you started with. So, you can use
import bge
scenes = bge.logic.getSceneList()
my_scene = [scene for scene in scenes if scene.name=="My Scene"][0]
object = my_scene.objects['My Object']