content/hifi-content/alan/dev/Scripts/Playa-Rover-v1.js
2022-02-13 20:41:08 +01:00

92 lines
No EOL
3 KiB
JavaScript

// playaRover-v1.js
// examples
//
// Created by Alan Zimmerman on 3/2/16
// Copyright 2016 High Fidelity, Inc.
//
// Spawns a simple rover/truck thing that can be conducted forwards and backwards and turned left and right
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
/*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */
HIFI_S3 = "http://hifi-content.s3.amazonaws.com/alan/dev/";
var roverURL = HIFI_S3 + "rover.fbx";
var roverCollisionURL = HIFI_S3 + "rover.obj";
var DISTANCE_IN_FRONT_OF_ME = 6.0;
function makeRover() {
var position = Vec3.sum(MyAvatar.position,
Vec3.multiplyQbyV(MyAvatar.orientation,
{ x: 0, y: 1.0, z: -DISTANCE_IN_FRONT_OF_ME }));
var rotation = Quat.multiply(MyAvatar.orientation,
Quat.fromPitchYawRollDegrees(0, -90, 0));
rover = Entities.addEntity({
type: "Model",
position: position,
rotation: rotation,
dimensions: { x: 7.00,
y: 3.00,
z: 3.00 },
dynamic: true,
modelURL: roverURL,
shapeType: "compound",
compoundShapeURL: roverCollisionURL,
velocity: {x: 0, y: -.01, z: 0},
gravity: {x: 0, y: -2.5 - Math.random() * 6, z: 0}
});
properties = Entities.getEntityProperties(rover);
}
makeRover();
function cleanup() {
Entities.deleteEntity(rover);
}
Script.scriptEnding.connect(cleanup);
/*
var rover;
function init() {
platform = Entities.addEntity({
name: "platform",
type: "Box",
position: { x: 0, y: 0, z: 0 },
dimensions: { x: 10, y: 2, z: 10 },
color: { red: 0, green: 0, blue: 255 },
gravity: { x: 0, y: 0, z: 0 },
visible: true,
locked: false,
lifetime: 6000,
velocity: { x: 1.0, y: 0, z: 0 },
damping: 0,
isDynamic: false
});
if (platform) {
if (MyAvatar.getParentID() != platform) {
MyAvatar.position = { x: 0, y: 3, z: 0 };
MyAvatar.setParentID(platform);
}
}
}
function update(dt) {
}
function shutdown() {
if (platform) {
MyAvatar.setParentID(0);
Entities.deleteEntity(platform);
}
}
Script.setTimeout(init, 3000);
Script.update.connect(update);
Script.scriptEnding.connect(shutdown);*/