0
$\begingroup$

I have a movable character in one scene (though it is a "2d" game, so it only moves left and right, up and down) and a camera is focused on it, but I need a camera in a different scene to copy the character's location in a parallel x-z plane. It will be my background scene and a perspective camera rather than an orthographic one. I have tried duplicating the scene with my character (my level) and then making everything invisible except the new background, but it never stays synchronized. In other words, I have researched and tried alternative ways to no success. Tell me if you need more info. Any advice helps!

[Edit after Monster's Include/Exclude edit]

This is what I have right now, but it's not working quite yet. for "Camera.master" I have this: Property for master camera It's called "camera," set to String, and has a value of zero.

My only guess was to do the same thing for all the other cameras I wanted to include, but that's clearly not the case.

$\endgroup$
1
$\begingroup$

Scenes have no "relation" to each other. You need to define a relationship by yourself.

I guess you want to mean the same relative coordinates or both cameras (example: the middle of one camera is the middle of the other camera). This shows an advanced example: https://youtu.be/rnjzoQM273A

I guess you do not need such high sophisticated solution. I simply assume:

  • The scale, orientation and location of both scenes is supposed to be the same and remains constant

This helps to simplify the system quite a lot.

It allows to copy the current world position (orientation and scale) from one scene to the other without converting it.

objectInSceneB.worldTransform = objectInSceneA.worldTransform.copy()

But there is a small but important issue. When you do it that way the target object might be rendered before it received the new position. That creates a one frame delay. While it does not sound a lot, it is very noticeable especially on cameras.

To solve that I created an invisible "master" object in one scene. Each scene (including the scene with the master) gets a visible "slave" object. Then I constantly copy from master to all slaves. This still creates a delay between the master and the slaves, but all slaves receive the change at the same time. As only slaves are visible there is no visible issue.

In your case I recommend following:

  • have one master camera (the user does not look through this camera) in one of the scenes [call it "Camera.master"]
  • have one slave camera at each single scene (= active cameras)
  • copy from master to all slaves

synchronizeCameras:

import bge

scenes = bge.logic.getSceneList()
slaveCameras = [scene.active_camera for scene in scenes]

for scene in scenes:
    masterCamera = scene.cameras.get("Camera.master")
    if masterCamera:
        masterKey = masterCamera.get("master")
        for slaveCamera in slaveCameras: 
            if slaveCamera.get("slave") == masterKey:
                slaveCamera.worldTransform = masterCamera.worldTransform.copy()

Installation

  • Copy the above code and paste it into a new textblock of your blend file. Name it synchronizeCameras.

  • Add an empty to any of the active scenes. Name it Synchronizer.camera. Switch to the logic editor.

    • Add an Always sensor. Enable True Level Triggering, to ensure it synchronizes at each single frame.

    • Add a Python controller in Script mode. Select synchronizeCameras. Connect it with the always sensor

enter image description here

  • Select the camera that should act as master camera (the camera you can move around)

    • Duplicate the camera shift-d.

      • Rename the new camera to "Camera.master" (the same name as in the script). This is the master camera. It is the camera that will determine the location of all slave cameras.
    • Select the other camera (where you copied from). This will be a slave.

      • Ensure this is the active camera of this scene ctrl + numpad 0. (You will never look through the master camera, you always look through the slave cameras).

      • Remove all logic bricks from this camera.

      • Un-parent the camera if it is parented (it should only move via the above code)

enter image description here

Run your game.

Include/exclude

[Edit]

To include/exclude slave candidates you can define a master key. At the master object setup a property "master" (e.g. String: "camera"). Then setup a property "slave" with the same value at each slave that should be synchronized. In your case do not setup the property slave at the camera of the overlay scene (or at least not with the same value).

This even works dynamically. You can change the properties in-game to enable/disable synchroinization on-the-fly.

$\endgroup$
  • $\begingroup$ Your link to the video doesn't work. I don't know if that was a mistake on your end or if they just took it down. The method you described should work for me though; I am trying it now. :) $\endgroup$ – DaDudeII Apr 12 '18 at 20:19
  • $\begingroup$ So I need to parent Camera.master to my character and keep all the other cameras unparented? $\endgroup$ – DaDudeII Apr 12 '18 at 20:51
  • $\begingroup$ Also I'm new to blender and have no idea where to plug in the script. :/ $\endgroup$ – DaDudeII Apr 12 '18 at 21:04
  • $\begingroup$ I fixed the link. It should work now. I added a section how to install the Python code. $\endgroup$ – Monster Apr 13 '18 at 9:05
  • $\begingroup$ Perfect. That's amazing! $\endgroup$ – DaDudeII Apr 13 '18 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.