This is an example of what I’d use if I want to have an object always be in the same world position as another object in my current scene. However, I want an object in my current scene to have the same world position as an object that is in a different scene (let’s say, scene “two”). How do I do that? I know it must be simple but I just can’t find it anywhere online.
I’m assuming instead of “scene = bge.logic.getCurrentScene()” it would be something like “scene = bge.logic.getsomeotherScene()” but I can’t figure it out. Could anyone help with this?
if 'otherScene' not in own
for scene in bge.logic.getSceneList():
if scene.name== 'NameOfScene':
own['otherScene']= scene
own['otherScene'].objects['objectOnOtherScene'].worldPosition=own.scene.objects['objectInMyScene'].worldPosition
I still can’t get this to work, and I don’t know why the code you two gave me is still hard to understand. Maybe it’s because it has no actual name of my scenes. Sorry still learning python.
My current scene (Scene I am in when starting the game) is called “game”
the other scene is “sun and moon”
the object in the current scene is “Empty”
the object in the “sun and moon” scene is… “sunGraphic”
so it should look like this?..
import bge
if ‘sun and moon’ not in own
for scene in bge.logic.getSceneList():
if scene.name== ‘game’:
own[‘sun and moon’]= scene
own[‘sun and moon’].objects[‘sunGraphic’].worldPosition=own.scene.objects[‘Empty’].worldPosition
from bge import logic
def get_scene(scene_name):
scenes = logic.getSceneList()
scene = None
for sce in scenes:
if sce.name == scene_name:
scene = sce
if scene == None:
print('
*** No scene found with the name: ' + str(scene_name) + ' ***
')
else:
return scene
def get_object(scene_name, object_name):
scene = get_scene(scene_name)
object = scene.objects[object_name]
return object
main_scene_object = get_object('Main_scene_name_here','the_object_name_here')
other_scene_object = get_object('Other_scene_name_here','the_other_object_name_here')
other_scene_object.worldPosition = main_scene_object.worldPosition