Problem with changing active camera

Added by Subeesh Basheer over 1 year ago

Hi, I'm facing a problem with changing the active camera once the space is loaded. My space contains 2 cameras:

<Camera Name="MainCamera" Enabled="False" FOV="60" ChaseDamping="60" ChaseStiffness="100" ChaseMass="5" Projection="Perspective" Position="0.4816188,1,0.3509535"/>
and
<Camera Name="camLoad" Enabled="False" FOV="60" ChaseDamping="60" ChaseStiffness="100" ChaseMass="5" Projection="Perspective" Rotation="0,6.275654,0" Position="2.458149,0.022083,-52.218924" />

'camLoad' is positioned in front of a primitive that acts as a loading screen, so once the space is loaded, I want to switch the active camera to 'MainCamera'. I've added a trigger that calls a LUA script that changes the camera:

<Trigger Event="Loaded" Target="SetCameraPos" />

<Script Name="SetCameraPos">
function main(obj, args)
--this calls a function in a plugin that adjusts the position of 'MainCamera'
komanager:SetCameraPosition()

scene.document.camera = 'MainCamera'
--the lines below hide the loading screen primitive.
scene:remove('LightLoad')
scene:remove('txtLoading')
scene:remove('boxLoadScreen')
scene.ui:writeline('Cam changed.')
end
&lt;/Script&gt;

The problem is that sometimes, when the space is loaded in the player, the view remains at the loading screen's (camLoad's) position even though the loading screen primitives are hidden. The line "Cam changed" appears in the debug window, indicating the LUA script was executed. Strangely, if I turn free look mode on and then off, the view jumps to the correct position (from MainCamera's perspective).
This problem tends to occur erratically - sometimes the camera changes without problems. Is there a bug that may be causing this issue, or is there any other way I can switch cameras that would not cause this problem?

Thanks for any insight into this!


Replies (1)

RE: Problem with changing active camera - Added by Jeremy Massey over 1 year ago

Hi Subeesh,

Subeesh Basheer wrote:

The problem is that sometimes, when the space is loaded in the player, the view remains at the loading screen's (camLoad's) position even though the loading screen primitives are hidden. The line "Cam changed" appears in the debug window, indicating the LUA script was executed. Strangely, if I turn free look mode on and then off, the view jumps to the correct position (from MainCamera's perspective). This problem tends to occur erratically - sometimes the camera changes without problems. Is there a bug that may be causing this issue, or is there any other way I can switch cameras that would not cause this problem?

This is a known bug, and seems to be related to changing the camera via a document "Loaded" trigger only.

A simple work around is to modify the properties of the current camera, rather than changing cameras. I've attached an example park demonstrating this behaviour. When the park is loaded, the camera's position and rotation are modified using:

scene:getelement('Camera').position = vector3()
scene:getelement('Camera').rotation = vector3()

I've included a large amount of primitives in the scene to increase the load time, so the change in the camera's position and rotation can be observed.

Jeremy

(1-1/1)