Skip to content

Instantly share code, notes, and snippets.

@ericrius1
Created April 9, 2015 18:57
Show Gist options
  • Save ericrius1/b0a71d1d7656d5f816a8 to your computer and use it in GitHub Desktop.
Save ericrius1/b0a71d1d7656d5f816a8 to your computer and use it in GitHub Desktop.
function followWaypoints() {
startingPosition = Entities.getEntityProperties(ship).position;
var currentProps = {
x: startingPosition.x,
y: startingPosition.y,
z: startingPosition.z,
}
var endProps = {
x: waypoints[
currentWaypointIndex].x,
y: waypoints[currentWaypointIndex].y,
z: waypoints[currentWaypointIndex].z,
}
var moveTween = new TWEEN.Tween(currentProps).
to(endProps, pointToPointTime).
easing(easingFunc).
onUpdate(function() {
Entities.editEntity(ship, {
position: {
x: currentProps.x,
y: currentProps.y,
z: currentProps.z
}
});
}).start();
moveTween.onComplete(function() {
currentWaypointIndex++;
if (currentWaypointIndex === waypoints.length) {
currentWaypointIndex = 0;
//If we've finished loop, then wait specified time to start over again
Script.setTimeout(function() {
followWaypoints();
}, waitTimeBetweenLoops)
} else {
Script.setTimeout(function() {
followWaypoints();
}, waitTimeBetweenStops)
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment