81 lines
No EOL
2.8 KiB
JavaScript
81 lines
No EOL
2.8 KiB
JavaScript
|
|
function GravityDanceBall(){};
|
|
var self;
|
|
|
|
GravityDanceBall.prototype = {
|
|
myUUID: null,
|
|
attracted: false,
|
|
force: false,
|
|
timer: 0,
|
|
preload: function(entityID){
|
|
self = this;
|
|
self.timer = 0;
|
|
self.myUUID = entityID;
|
|
print("Script Load Complete");
|
|
},
|
|
update: function(dt){
|
|
if(self.attracted){ // Double safe guard to avoid someracing issues
|
|
self.timer += dt;
|
|
|
|
if(self.timer> 0.0333333333333333){
|
|
self.timer = 0;
|
|
|
|
try{
|
|
var entity = Entities.getEntityProperties(self.myUUID);
|
|
// Up should be the Avatars Reverse FWD: We want the feet point downsssssssssssd
|
|
var up = Quat.getUp(entity.rotation);
|
|
|
|
//lookAt(const glm::vec3& eye, const glm::vec3& center, const glm::vec3& up)
|
|
//LookAt( Orientation of Current Object, Orientation of Target, Directionality)
|
|
MyAvatar.orientation = Quat.multiply(Quat.lookAt(MyAvatar.position, entity.position, up), Quat.fromVec3Degrees({x:90,y:0,z:0}));
|
|
}catch(e){
|
|
print("Failed to sustain update, reset " + e);
|
|
Script.update.disconnect(self.update);
|
|
self.attracted = false;
|
|
}
|
|
}
|
|
}
|
|
},
|
|
clickDownOnEntity: function (entityId, mouseEvent){
|
|
if(mouseEvent.button === "LEFT"){
|
|
if(self.attracted){
|
|
self.attracted = false; // lets just flip this before to cancel it.
|
|
print("Unattract");
|
|
try{
|
|
Script.update.disconnect(self.update);
|
|
|
|
// Dettach.
|
|
MyAvatar.setParentID(null);
|
|
|
|
}catch(e){
|
|
print("Disconnect Event encountered an error: " + e)
|
|
}finally{
|
|
// Cant be 0, so.
|
|
MyAvatar.orientation = Quat.fromVec3Degrees({x:0,y:0,z:0});
|
|
// Thrust Avatar Down (relatively)
|
|
MyAvatar.addThrust({x:0, y: -1000, z: 0});
|
|
}
|
|
}else{
|
|
self.attracted = true; // lets just flip this before to cancel it.
|
|
print("Attract");
|
|
MyAvatar.setParentID(self.myUUID);
|
|
try{
|
|
print("Connecting");
|
|
Script.update.connect(self.update);
|
|
// Thrust Avatar Down (relatively)
|
|
print("Connected");
|
|
MyAvatar.addThrust({x:0,y: -100000, z: 0});
|
|
|
|
print("Force Push");
|
|
}catch(e){
|
|
print("Connect Event encountered an error: " + e)
|
|
MyAvatar.orientation = Quat.fromVec3Degrees({x:0,y:0,z:0});
|
|
self.attracted = false; // lets just flip this before to cancel it.
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
GravityDanceBallObject = function(){ return new GravityDanceBall()} |