mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 13:33:38 +02:00
Merge pull request #7477 from ericrius1/cowTipper
Adds a cow which untips itself and moos when it collides with an entity
This commit is contained in:
commit
7db22ee8c2
2 changed files with 121 additions and 0 deletions
68
examples/cows/cowEntityScript.js
Normal file
68
examples/cows/cowEntityScript.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
|
||||
// cowEntityScript.js
|
||||
// examples/cows
|
||||
//
|
||||
// Created by Eric Levin on 3/25/16
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// This entity script handles the logic for untipping a cow after it collides with something
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
Script.include("../libraries/utils.js");
|
||||
|
||||
var _this = this;
|
||||
_this.COLLISION_COOLDOWN_TIME = 5000;
|
||||
|
||||
|
||||
this.preload = function(entityID) {
|
||||
print("EBL Preload!!");
|
||||
_this.entityID = entityID;
|
||||
_this.mooSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/moo.wav")
|
||||
_this.mooSoundOptions = {volume: 0.7, loop: false};
|
||||
_this.timeSinceLastCollision = 0;
|
||||
_this.shouldUntipCow = true;
|
||||
}
|
||||
|
||||
this.collisionWithEntity = function(myID, otherID, collisionInfo) {
|
||||
if(_this.shouldUntipCow) {
|
||||
Script.setTimeout(function() {
|
||||
_this.untipCow();
|
||||
_this.shouldUntipCow = true;
|
||||
}, _this.COLLISION_COOLDOWN_TIME);
|
||||
}
|
||||
|
||||
_this.shouldUntipCow = false;
|
||||
|
||||
}
|
||||
|
||||
this.untipCow = function() {
|
||||
// keep yaw but reset pitch and roll
|
||||
var cowProps = Entities.getEntityProperties(_this.entityID, ["rotation", "position"]);
|
||||
var eulerRotation = Quat.safeEulerAngles(cowProps.rotation);
|
||||
eulerRotation.x = 0;
|
||||
eulerRotation.z = 0;
|
||||
var newRotation = Quat.fromVec3Degrees(eulerRotation);
|
||||
Entities.editEntity(_this.entityID, {
|
||||
rotation: newRotation,
|
||||
velocity: {x: 0, y: 0, z: 0},
|
||||
angularVelocity: {x: 0, y: 0, z:0}
|
||||
});
|
||||
|
||||
|
||||
_this.mooSoundOptions.position = cowProps.position;
|
||||
if (!_this.soundInjector) {
|
||||
_this.soundInjector = Audio.playSound(_this.mooSound, _this.mooSoundOptions);
|
||||
} else {
|
||||
_this.soundInjector.setOptions(_this.mooSoundOptions);
|
||||
_this.soundInjector.restart();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
53
examples/cows/cowSpawner.js
Normal file
53
examples/cows/cowSpawner.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
|
||||
// cowSpawner.js
|
||||
// examples/cows
|
||||
//
|
||||
// Created by Eric Levin on 3/25/16
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// This spawns a cow which will untip itself
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var orientation = MyAvatar.orientation;
|
||||
orientation = Quat.safeEulerAngles(orientation);
|
||||
orientation.x = 0;
|
||||
orientation = Quat.fromVec3Degrees(orientation);
|
||||
var center = Vec3.sum(MyAvatar.getHeadPosition(), Vec3.multiply(2, Quat.getFront(orientation)));
|
||||
|
||||
|
||||
var SCRIPT_URL = Script.resolvePath("cowEntityScript.js?");
|
||||
var cow = Entities.addEntity({
|
||||
type: "Model",
|
||||
modelURL: "http://hifi-content.s3.amazonaws.com/DomainContent/production/cow/newMooCow.fbx",
|
||||
name: "playa_model_throwinCow",
|
||||
position: center,
|
||||
animation: {
|
||||
currentFrame: 278,
|
||||
running: true,
|
||||
url: "http://hifi-content.s3.amazonaws.com/DomainContent/Junkyard/Playa/newMooCow.fbx"
|
||||
},
|
||||
dimensions: {
|
||||
x: 0.739,
|
||||
y: 1.613,
|
||||
z: 2.529
|
||||
},
|
||||
dynamic: true,
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: -5,
|
||||
z: 0
|
||||
},
|
||||
shapeType: "box",
|
||||
script: SCRIPT_URL,
|
||||
userData: "{\"grabbableKey\":{\"grabbable\":true}}"
|
||||
});
|
||||
|
||||
|
||||
function cleanup() {
|
||||
Entities.deleteEntity(cow);
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(cleanup);
|
Loading…
Reference in a new issue