Fectar Blocks core primitive types
// Set a clicked spot to x,y,z-coordinates: (0, 0.5, 1).
function onClick(eventParams)
{
eventParams.spot.position = new Vector3(0, 0.5, 1);
}
// Detect if spot 'mySpot' is behind the camera.
setInterval(()=> {
var mySpot = Space.getSpot('mySpot');
var offset = mySpot.position - Space.camera.position;
if (Vector3.Dot(Space.camera.forward, offset) < 0)
log('Object is behind me');
else
log('Object is in front of me');
}, 1000);
All debug related functions and constants.
// Log the name of a clicked spot.
function onClick(eventParams)
{
log(eventParams.spot.name);
}
All event related functions and constants.
// Implement an onClick event handler like this, to catch all clicks and taps.
// This example hides the spot that was clicked.
function onClick(eventParams)
{
eventParams.spot.hide();
}
Let's get physical
Everything space related
// Set position of a spot named 'mySpot' to (0,0,0) when clicked.
function onClick(eventParams)
{
let clickedSpot = eventParams.spot;
if (clickedSpot.name == 'mySpot')
clickedSpot.position = Vector3.zero;
}
// Make any clicked spot always turn towards the camera when clicked.
function onClick(eventParams)
{
eventParams.spot.facingCameraStart();
}
// Move spot mySpot to the position of a spot myTarget within 2 seconds. Hide mySpot when target is reached.
function onClick(eventParams)
{
let clickedSpot = eventParams.spot;
if (clickedSpot.name == 'mySpot')
clickedSpot.moveTo(Space.getSpot('myTarget').position, 2, function(){
clickedSpot.hide();
});
}
// Go through all spots in the space and place them next to eachother.
for (let i = 0; i < Space.spots.length; i++)
Space.spots[i].position = new Vector3(i, 0, 0);
// Get the spot named 'mySpot' and write the position to the log.
log(Space.getSpot('mySpot').position);
All time related functions and constants.
Example 1:
// Create a log entry every 5 seconds
setInterval(() => log('Another 5 seconds have passed.'), 5000);
Example 2:
// Rotate three spots to create a realtime analog clock
let hands = ['hourHand', 'minutesHand', 'secondsHand'];
// Get spot instances based on the names in the hands array
let hourSpot = Space.getSpot(hands[0]);
let minuteSpot = Space.getSpot(hands[1]);
let secondSpot = Space.getSpot(hands[2]);
// Set interval to update the clock every 1000 milliseconds (1 second)
setInterval(() => {
// Get the current time
let now = new Date();
let seconds = now.getSeconds();
let minutes = now.getMinutes();
let hours = now.getHours() + (minutes / 60);
// Get the rotations based on the time
let rotationHours = Quaternion.Euler(0, 0, hours / 12 * 360);
let rotationMinutes = Quaternion.Euler(0, 0, minutes / 60 * 360);
let rotationSeconds = Quaternion.Euler(0, 0, seconds / 60 * 360);
// Rotate around Z
hourSpot.rotation = rotationHours;
minuteSpot.rotation = rotationMinutes;
secondSpot.rotation = rotationSeconds;
// Position the spots
hourSpot.position = rotationHours * Vector3.up;
minuteSpot.position = rotationMinutes * Vector3.up;
secondSpot.position = rotationSeconds * Vector3.up;
}, 1000);
// Hide and show 'mySpot' every 500 milliseconds for a total of 3 seconds.
let mySpot = Space.getSpot('mySpot');
// Toggle visibility every 500 ms and store a handle to the interval in myInterval.
let myInterval = setInterval(() => mySpot.isVisible = !mySpot.isVisible, 500);
// Clear the interval after 3 seconds have passed.
setTimeout(() => {
clearInterval(myInterval);
// Make sure the spot is visible at the end of this blinking sequence.
mySpot.isVisible = true;
}, 3000);
All utility related functions and constants.
Video killed the radio star
Old Version | New Version | |||||
---|---|---|---|---|---|---|
Nr | Module | Script | Nr | Module | Script | |
<= v0.2.2a | global | spotId | => | v0.2.3a | Event | Event.spot.name |
<= v0.2.2a | Debug | String test(Number) | => | v0.2.3a | none | none |