Setting camera's position if it passes a threshold height

31 views
Skip to first unread message

Sean Naughton

unread,
Sep 6, 2017, 1:18:18 PM9/6/17
to CoSpaces Scripting
Howdy,

I'm looking to move the camera to a spawn point when it passes a threshold height. I'm capable of this with JavaScript but not Blockly (examples below). In my test space, I'm working on doing this when the camera moves above the man.

Any thoughts on implementation for Blockly would be great. Thanks!


Blockly: Producing Error "Maximum call stack size exceeded" (I believe this is stemming from wrapping the "if position, then move" within an infinite loop, but not sure how else to accomplish this without an event)


JavaScript: Working

var camera = Scene.getItem("NLiJADMFTY");
var man = Scene.getItem("z4KFcETiFZ");
var spawnPosition = Scene.getItem("67COX9XawK").getPosition();


Scene.scheduleRepeating(function() {
   
if (camera.getPosition().z >= man.getPosition().z) {
        camera
.moveLinear(spawnPosition.x, spawnPosition.y, spawnPosition.z, .001);
   
}
}, 1);



Thanks again,
Sean

Benjamin Singh

unread,
Sep 7, 2017, 3:03:11 AM9/7/17
to CoSpaces Scripting
Hi Sean,

if you encounter this error using a (infinite-)loop try to add one "pause for x sec." block to your code like this:


Internally the Blockly code here is different from the JavaScript code using Scene.scheduleRepeating()


Benjamin




Sean Naughton

unread,
Sep 7, 2017, 8:18:44 AM9/7/17
to CoSpaces Scripting
Thanks Benjamin.

We started noticing the Pause block helping in some situations. Great to have the validation.

Thanks again!

Sean

Benjamin Singh

unread,
Sep 7, 2017, 8:26:54 AM9/7/17
to CoSpaces Scripting
Hi Sean,

we are looking into possibilities to add a separate block (maybe an event) where users can put their logic which should be executed for every frame. Till then you can do it like above.

Benjamin
Reply all
Reply to author
Forward
0 new messages