Friday, November 17, 2006
The AI
That morass of code was a snippet of the functionality for my in game enemy AI.
Crazy...
Crazy...
Some code...
var speed = 17;
var gravity = 10;
var layerMask = 1 << 8;
var e_rand = 0;
var timex;
var nextMoveTime = 0.0;
var d_counter = 0;
var moveDelay = 5;
var bloat_rand = 4;
var controller : CharacterController;
private var moveDirection = Vector3.zero;
function Update ()
{
var locn = -1;
var loci = -1;
var master_object = GameObject.Find("/MasterGO");
var master_script : MasterGOinit;
master_script = master_object.GetComponent (MasterGOinit);
var hit : RaycastHit;
var ehit : RaycastHit;
//var hit2 : RaycastHit;
var controller : CharacterController = GetComponent(CharacterController);
e_rand = Random.Range(1, 5);
e_rand = Mathf.Round(e_rand);
//bloat_rand = Random.Range(1, 4);
timex = Time.deltaTime * 10;
if (nextMoveTime == 0){
nextMoveTime = Time.time;}
if ((controller.collisionFlags & CollisionFlags.Sides) != 0){
master_script.burgerman = 0;
master_script.respawnb = 1;
counter = master_script.bcount;
counter --;
master_script.bcount = counter;
Destroy(gameObject);}
if (d_counter > 10){
master_script.burgerman = 0;
master_script.respawnb = 1;
counter = master_script.bcount;
counter --;
master_script.bcount = counter;
Destroy(gameObject);}
// if (!(controller.transform.position.x < -64 || controller.transform.position.x > 56 || controller.transform.position.z < -101 || controller.transform.position.z > 20)){
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);//}
Debug.DrawRay (transform.position, Vector3.forward);
locn = master_script.opos[1];
loci = master_script.opos[0];
switch(0){
case 1:
loci++;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(-speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[0] = master_script.opos[0] + 1;}
break;
case 2:
loci--;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[0] = master_script.opos[0] - 1;}
break;
case 3:
locn++;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(0, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[1] = master_script.opos[1] + 1;}
case 4:
locn--;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(0, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[1] = master_script.opos[1] - 1;}
break;
}
ehit = hit;
switch (e_rand){
case 1:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.forward,hit,10)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.forward,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, speed));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("forward!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, speed));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
case 2:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.back,hit,12)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.back,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, -speed));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("back!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, -speed));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
case 3:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.right,hit,10)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.right,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("right!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "mainman") && (ehit.collider.name != "shoeman(Clone)") && (ehit.collider.name != "burgerman(Clone)") && (ehit.collider.name != "oilman(Clone)")){
controller.Move(Vector3(speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
case 4:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.left,hit,10)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.left,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(-speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("left!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "mainman") && (ehit.collider.name != "shoeman(Clone)") && (ehit.collider.name != "burgerman(Clone)") && (ehit.collider.name != "oilman(Clone)")){
controller.Move(Vector3(-speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
}
}
function Awake ()
{
var controller : CharacterController = GetComponent(CharacterController);
if (!controller)
gameObject.AddComponent("CharacterController");
nextMoveTime = Time.time;
}
var gravity = 10;
var layerMask = 1 << 8;
var e_rand = 0;
var timex;
var nextMoveTime = 0.0;
var d_counter = 0;
var moveDelay = 5;
var bloat_rand = 4;
var controller : CharacterController;
private var moveDirection = Vector3.zero;
function Update ()
{
var locn = -1;
var loci = -1;
var master_object = GameObject.Find("/MasterGO");
var master_script : MasterGOinit;
master_script = master_object.GetComponent (MasterGOinit);
var hit : RaycastHit;
var ehit : RaycastHit;
//var hit2 : RaycastHit;
var controller : CharacterController = GetComponent(CharacterController);
e_rand = Random.Range(1, 5);
e_rand = Mathf.Round(e_rand);
//bloat_rand = Random.Range(1, 4);
timex = Time.deltaTime * 10;
if (nextMoveTime == 0){
nextMoveTime = Time.time;}
if ((controller.collisionFlags & CollisionFlags.Sides) != 0){
master_script.burgerman = 0;
master_script.respawnb = 1;
counter = master_script.bcount;
counter --;
master_script.bcount = counter;
Destroy(gameObject);}
if (d_counter > 10){
master_script.burgerman = 0;
master_script.respawnb = 1;
counter = master_script.bcount;
counter --;
master_script.bcount = counter;
Destroy(gameObject);}
// if (!(controller.transform.position.x < -64 || controller.transform.position.x > 56 || controller.transform.position.z < -101 || controller.transform.position.z > 20)){
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);//}
Debug.DrawRay (transform.position, Vector3.forward);
locn = master_script.opos[1];
loci = master_script.opos[0];
switch(0){
case 1:
loci++;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(-speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[0] = master_script.opos[0] + 1;}
break;
case 2:
loci--;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[0] = master_script.opos[0] - 1;}
break;
case 3:
locn++;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(0, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[1] = master_script.opos[1] + 1;}
case 4:
locn--;
if ((master_script.mastergridx[loci] == 1 && master_script.mastergridy[locn] == 1) && !(locn > 8) && !(locn < 0) && !(loci > 8) && !(loci < 0)){
controller.Move(Vector3(0, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;
master_script.opos[1] = master_script.opos[1] - 1;}
break;
}
ehit = hit;
switch (e_rand){
case 1:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.forward,hit,10)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.forward,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, speed));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("forward!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, speed));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
case 2:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.back,hit,12)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.back,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, -speed));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("back!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(0, 0, -speed));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
case 3:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.right,hit,10)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.right,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("right!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "mainman") && (ehit.collider.name != "shoeman(Clone)") && (ehit.collider.name != "burgerman(Clone)") && (ehit.collider.name != "oilman(Clone)")){
controller.Move(Vector3(speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
case 4:
if ((Time.time > nextMoveTime) && Physics.Raycast((transform.position + Vector3(0,-15,0)),Vector3.left,hit,10)){
Physics.Raycast(transform.position + Vector3(0,15,0), Vector3.left,ehit);
if ((hit.collider.name == "NatureTile - 1(Clone)") || (hit.collider.name == "NatureTile - 2 - Smooth(Triangle)(Clone)") || (hit.collider.name == "NatureTile - 3(Clone)")){
if ((ehit.collider.name != "MCube") && (ehit.collider.name != "Scube") && (ehit.collider.name != "BCube") && (ehit.collider.name != "OCube")){
controller.Move(Vector3(-speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
Debug.Log("left!");
}
else if ((hit.collider.name == "burgertime - Tile(Clone)") || (hit.collider.name == "oil_refinery - Tile(Clone)") || (hit.collider.name == "shoefactory - Tile(Clone)")){
if ((ehit.collider.name != "mainman") && (ehit.collider.name != "shoeman(Clone)") && (ehit.collider.name != "burgerman(Clone)") && (ehit.collider.name != "oilman(Clone)")){
controller.Move(Vector3(-speed, 0, 0));
nextMoveTime = nextMoveTime + moveDelay;}
}
}
break;
}
}
function Awake ()
{
var controller : CharacterController = GetComponent(CharacterController);
if (!controller)
gameObject.AddComponent("CharacterController");
nextMoveTime = Time.time;
}
Thursday, November 16, 2006
Oilrefinery Tile Texture
These are the final textures that will be used for the oil refinery tile. There is only one more addition that I have to work on that has been unannounced onto the blog.. This will be updated soon.
- Adam
Monday, November 13, 2006
ShoeFactory Tile Texture
This is the Shoefactory Tile that I have been texturing lately. I only have one tile left and its the oil refinery. I will post more information soon as I finish.
- Adam
Sunday, November 12, 2006
Functional AI!
Corporate machinations are afoot!
The AI (well, it's not really AI...just an event driven script, but whatever) is functional!
Sunday, November 05, 2006
Farm Nature Tile
The Nature tiles are finished with the completion of this tile and I am glad. But yet, there is more yet to finish.. egh.
- Adam
Friday, November 03, 2006
Desert Nature Tile
After many layers later, I have finally completed the Desert Nature Tile. This one so far has been my favorite since I love the colors as they bounce and reflect off of the water pool.
- Adam
Burger Shanty Tile
Finally, what I have left to show so far is the Burger Shanty in all its glory. Enjoy these renders of the final textured images.
- Adam