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

143 lines
No EOL
4.4 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 roverbackwheelsURL = HIFI_S3 + "rover-backwheels.fbx";
var roverbackwheelsCollisionURL = HIFI_S3 + "rover-backwheels.obj";
var roverfrontwheelsURL = HIFI_S3 + "rover-frontwheels.fbx";
var roverfrontwheelsCollisionURL = HIFI_S3 + "rover-frontwheels.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.5, 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,
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}
});
}
function makeRoverBackWheels() {
var position = Vec3.sum(MyAvatar.position,
Vec3.multiplyQbyV(MyAvatar.orientation,
{ x: 0, y: -1.0, z: -DISTANCE_IN_FRONT_OF_ME - 4 }));
var rotation = Quat.multiply(MyAvatar.orientation,
Quat.fromPitchYawRollDegrees(0, -90, 0));
roverbackwheels = Entities.addEntity({
type: "Model",
position: position,
rotation: rotation,
dynamic: true,
modelURL: roverbackwheelsURL,
shapeType: "compound",
compoundShapeURL: roverbackwheelsCollisionURL,
velocity: {x: 0, y: -.01, z: 0},
gravity: {x: 0, y: -2.5 - Math.random() * 6, z: 0}
});
}
function makeRoverFrontWheels() {
var position = Vec3.sum(MyAvatar.position,
Vec3.multiplyQbyV(MyAvatar.orientation,
{ x: 0, y: -1.0, z: -DISTANCE_IN_FRONT_OF_ME + 5 }));
var rotation = Quat.multiply(MyAvatar.orientation,
Quat.fromPitchYawRollDegrees(0, -90, 0));
roverfrontwheels = Entities.addEntity({
type: "Model",
position: position,
rotation: rotation,
dynamic: true,
modelURL: roverfrontwheelsURL,
shapeType: "compound",
compoundShapeURL: roverfrontwheelsCollisionURL,
velocity: {x: 0, y: -.01, z: 0},
gravity: {x: 0, y: -2.5 - Math.random() * 6, z: 0}
});
}
makeRover();
makeRoverBackWheels();
makeRoverFrontWheels();
function cleanup() {
Entities.deleteEntity(rover);
Entities.deleteEntity(roverbackwheels);
Entities.deleteEntity(roverfrontwheels);
}
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);*/