Created
August 24, 2017 20:18
-
-
Save nkallen/f8146a2282152e78feae2b813197c5ba to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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