44 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2014-10-24 16:38:24 -07:00
//
// TourGuide.js
//
// This script will follow another person, if their display name is "Tour Guide"
//
var leaderName = "Tour Guide";
var guide;
var isGuide = false;
var lastGuidePosition = { x:0, y:0, z:0 };
var MIN_CHANGE = 2.0;
var LANDING_DISTANCE = 2.0;
var LANDING_RANDOM = 0.2;
var relativePosition;
2014-10-24 16:38:24 -07:00
function update(deltaTime) {
2014-10-24 17:10:46 -07:00
if (Math.random() < deltaTime) {
guide = AvatarList.avatarWithDisplayName(leaderName);
if (guide && !isGuide) {
2014-10-26 21:18:54 -07:00
print("Found a tour guide!");
2014-10-24 17:10:46 -07:00
isGuide = true;
2014-10-26 21:18:54 -07:00
} else if (!guide && isGuide) {
2014-10-24 17:10:46 -07:00
print("Lost My Guide");
isguide = false;
2014-10-24 16:38:24 -07:00
}
2014-10-24 17:10:46 -07:00
}
2014-10-24 16:38:24 -07:00
2014-10-24 17:10:46 -07:00
if (guide) {
relativePosition = Vec3.subtract(MyAvatar.position, lastGuidePosition);
2014-10-24 17:10:46 -07:00
// Check whether guide has moved, update if so
if (Vec3.length(lastGuidePosition) == 0.0) {
lastGuidePosition = guide.position;
} else {
if (Vec3.length(Vec3.subtract(lastGuidePosition, guide.position)) > MIN_CHANGE) {
var newPosition = Vec3.sum(guide.position, relativePosition);
2014-10-24 17:10:46 -07:00
MyAvatar.position = newPosition;
lastGuidePosition = guide.position;
}
2014-10-24 16:38:24 -07:00
}
2014-10-24 17:10:46 -07:00
}
2014-10-24 16:38:24 -07:00
}
Script.update.connect(update);