Skip to content

Instantly share code, notes, and snippets.

@nkallen
Created August 24, 2017 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nkallen/f8146a2282152e78feae2b813197c5ba to your computer and use it in GitHub Desktop.
Save nkallen/f8146a2282152e78feae2b813197c5ba to your computer and use it in GitHub Desktop.
function main(gameBuilder) {
var entity = gameBuilder.Entity("Max_rootNode")
// MARK: - Behaviors & Goals
var agent = entity.Agent("Max")
agent.mass = 1
agent.maxAcceleration = 1
agent.maxSpeed = 1
agent.radius = 0.5
var followBehavior = agent.Behavior()
followBehavior.avoidObstacles(5)
followBehavior.wander(1)
followBehavior.seekAgent("player")
var flockBehavior = agent.Behavior()
flockBehavior.avoidObstacles(0.5)
flockBehavior.alignWith(["Max"], 2, 1)
flockBehavior.separateFrom(["Max"], 2, 1)
flockBehavior.cohereWith(["Max"], 2, 1)
// MARK: - Triggers
entity.onLoad = function(self, root) {
self.playAnimation("idle.scn")
}
var flock = true
entity.onSelect = function(self, root) {
flock = !flock
self.stopAnimation("idle.scn", 0.1)
self.playAnimation("walk.scn")
if (flock) {
self.setBehaviorWeight(followBehavior, 0)
self.setBehaviorWeight(flockBehavior, 1)
} else {
self.setBehaviorWeight(followBehavior, 1)
self.setBehaviorWeight(flockBehavior, 0)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment