mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 22:45:17 +02:00
Deprecate globalCollisionsExample.js, and add entityCollisionExample.js
This commit is contained in:
parent
c9932a5cf2
commit
09e9d353ea
2 changed files with 56 additions and 14 deletions
53
examples/example/entityCollisionExample.js
Normal file
53
examples/example/entityCollisionExample.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
//
|
||||
// globalCollisionsExample.js
|
||||
// examples
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 1/29/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// This is an example script that demonstrates use of the Controller class
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
function someCollisionFunction(entityA, entityB, collision) {
|
||||
print("collision: " + JSON.stringify({a: entityA, b: entityB, c: collision}));
|
||||
}
|
||||
|
||||
var position = Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation));
|
||||
var properties = {
|
||||
type: "Box",
|
||||
position: position,
|
||||
collisionsWillMove: true,
|
||||
color: { red: 200, green: 0, blue: 0 }
|
||||
};
|
||||
var collider = Entities.addEntity(properties);
|
||||
var armed = false;
|
||||
function togglePrinting() {
|
||||
print('togglePrinting from ' + armed + ' on ' + collider);
|
||||
if (armed) {
|
||||
Script.removeEventHandler(collider, "collisionWithEntity", someCollisionFunction);
|
||||
} else {
|
||||
Script.addEventHandler(collider, "collisionWithEntity", someCollisionFunction);
|
||||
}
|
||||
armed = !armed;
|
||||
print("Red box " + (armed ? "will" : "will not") + " print on collision.");
|
||||
}
|
||||
togglePrinting();
|
||||
|
||||
properties.position.y += 0.2;
|
||||
properties.color.blue += 200;
|
||||
// A handy target for the collider to hit.
|
||||
var target = Entities.addEntity(properties);
|
||||
|
||||
properties.position.y += 0.2;
|
||||
properties.color.green += 200;
|
||||
var button = Entities.addEntity(properties);
|
||||
Script.addEventHandler(button, "clickReleaseOnEntity", togglePrinting);
|
||||
|
||||
Script.scriptEnding.connect(function () {
|
||||
Entities.deleteEntity(collider);
|
||||
Entities.deleteEntity(target);
|
||||
Entities.deleteEntity(button);
|
||||
});
|
|
@ -12,17 +12,6 @@
|
|||
//
|
||||
|
||||
|
||||
print("hello...");
|
||||
|
||||
|
||||
function entityCollisionWithEntity(entityA, entityB, collision) {
|
||||
print("entityCollisionWithParticle()..");
|
||||
print(" entityA.getID()=" + entityA.id);
|
||||
print(" entityB.getID()=" + entityB.id);
|
||||
Vec3.print('penetration=', collision.penetration);
|
||||
Vec3.print('contactPoint=', collision.contactPoint);
|
||||
}
|
||||
|
||||
Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity);
|
||||
|
||||
print("here... hello...");
|
||||
print("The is obsolete. Please instead use:");
|
||||
print(" the collisionSoundURL property on entities, or");
|
||||
print(" entityCollisionExample.js");
|
||||
|
|
Loading…
Reference in a new issue