frogger example

60 views
Skip to first unread message

Outpost 31

unread,
Aug 12, 2017, 2:16:52 AM8/12/17
to CoSpaces Scripting
Hi, I was looking at your frogger example below and when I implement it the bus just hits me and warps back to its original position.  Just wondering how to fix this and as well if there is a way to implement this in blockly as that would be easier for my students to understand.  Secondly is it possible to implement  the other script you mentioned on that thread in blockly as well? (I placed that below this frogger script) thanks for any help

// get camrea object
var cam = Scene.getCamera();

// create bus and set its rotation
var bus = Scene.createItem('LP_Bus', -10, 10, 0);
bus.addLocalRotation(0, 0, 0, 0, 0, 1, Math.PI / 2);

// set onCollisionEnter handler
bus.onCollisionEnter(function() {
    // if bus collides with cam then move the cam back to the origin of the scene
    cam.setPosition(0, 30, 1.5);
});

// update position of the bus (make it drive)
var xPos = -10; 
Scene.scheduleRepeating(function() {
    xPos += 0.1;
    if(xPos > 10) {
        xPos = -10;
    }
    bus.setPosition(xPos, 10, 0);
}, 0);



var startPos = {x: 0, y: 0, z: 20};
var cam = Scene.getCamera();
var camPos;

Scene.scheduleRepeating(function() {
    camPos = cam.getPosition();
    if(camPos.z < 5) {
        cam.setPosition(startPos.x, startPos.y, startPos.z);
    }
}, 0);

Benjamin Singh

unread,
Sep 4, 2017, 9:47:10 AM9/4/17
to CoSpaces Scripting
Hi,

that script seems not to be correct.

Link to example: https://cospac.es/XeDF

However, it's actually very easy to implement the same behaviour in Blockly as well. Have a look:


Example space: https://cospac.es/b5XV


Benjamin


Outpost 31

unread,
Sep 5, 2017, 12:18:23 AM9/5/17
to CoSpaces Scripting
Great thanks, what is the exit space for?

Benjamin Singh

unread,
Sep 5, 2017, 5:36:03 AM9/5/17
to CoSpaces Scripting
Hi,

have a look at this example:




The code in Enter will be executed when the objects are intersecting, otherwise the code in Exit will be executed.


Benjamin




Outpost 31

unread,
Sep 8, 2017, 11:23:40 PM9/8/17
to CoSpaces Scripting
Awesome, thnx for the example
Reply all
Reply to author
Forward
0 new messages