Created
April 9, 2015 18:57
-
-
Save ericrius1/b0a71d1d7656d5f816a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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