From a71c8795d6fd89c04f501de7745aa61429398f1a Mon Sep 17 00:00:00 2001 From: Brett Unzaga Date: Thu, 28 Nov 2013 01:56:39 -0700 Subject: [PATCH] Fixed the pathing bug I created by moving script to Zombie.js --- js/loadScene.js | 2 ++ lib/Zombie.js | 17 ++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/js/loadScene.js b/js/loadScene.js index 98f5cea..8d70e5e 100644 --- a/js/loadScene.js +++ b/js/loadScene.js @@ -145,11 +145,13 @@ require([ var z1 = Zombie.getRef(); z1.transformComponent.setTranslation(4,0,4); z1.transformComponent.setUpdated(); + z1.aIComponent.getBehaviorByName("Idle").state = 0; z1.skip = false; var z2 = Zombie.getRef(); z2.transformComponent.setTranslation(-4,0,-4); z2.transformComponent.setUpdated(); + z2.aIComponent.getBehaviorByName("Idle").state = 0; z2.skip = false; goo.renderer.setClearColor(0, 0, 0, 1); diff --git a/lib/Zombie.js b/lib/Zombie.js index 0a537ea..e5c999b 100644 --- a/lib/Zombie.js +++ b/lib/Zombie.js @@ -36,7 +36,7 @@ define([ Zombie.getRef = function(){ if(zRef.length > 0){ var z = zRef.shift(); - + z.healthComponent.resetHealth(); return z; } } @@ -71,7 +71,7 @@ define([ z.setComponent(new AIComponent(z)); z.setComponent(new HealthComponent(z, health)); z.aIComponent.addBehavior({name:"Death", update:Zombie.Death, blocking:true, active:false}, 0); - z.aIComponent.addBehavior({name:"Idle", update:Zombie.Idle, blocking:true, active:false}, 10); + z.aIComponent.addBehavior({name:"Idle", update:Zombie.Idle, blocking:true, active:true}, 10); z.aIComponent.addBehavior({name:"PathFind", update:Zombie.PathFind, blocking:true, active:false}, 20); z.skip = true; zRef.push(z); @@ -98,10 +98,12 @@ define([ entity.aIComponent.getBehaviorByName("Idle").state = -1; entity.aIComponent.getBehaviorByName("Idle").active = true; entity.aIComponent.getBehaviorByName("PathFind").active = false; - entity.healthComponent.resetHealth(); - node.state = null; + + node.state = -1; zRef.push(entity); + var z = Zombie.getRef(); + z.aIComponent.getBehaviorByName("Idle").active = true; z.aIComponent.getBehaviorByName("Idle").state = 0; z.transformComponent.setTranslation((Math.random()*10)-5,0,(Math.random()*10)-5); z.transformComponent.setUpdated(); @@ -136,9 +138,10 @@ define([ // if player near... node.active = false; entity.aIComponent.getBehaviorByName("PathFind").active = true; + console.log("pathfinding"); break; default: - node.state = 0; + node.state = -1; break; } }; @@ -228,7 +231,7 @@ define([ break; case 2: if(entity.transformComponent.transform.translation.distance(Game.userEntity.transformComponent.transform.translation) <= 1.0){ - console.log("at player position..."); + //console.log("at player position..."); node.state = 3; } @@ -242,7 +245,7 @@ define([ entity.transformComponent.setUpdated(); break; case 3: - entity.aIComponent.setActiveByName("Zombie-Idle", true); + entity.aIComponent.getBehaviorByName("Idle").active = true; break; case 4: node.goalRoom = Game.userEntity.room;