3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: 1 [2]

Author Topic: Zombie AIs, a new idea  (Read 1276 times)

« Reply #15 on: June 14, 2012, 11:25:20 AM »
Anyways, do you have a lil script you could share for the large amount of zombies?

Sure, here you go.

Code: [Select]
float TotalZombies = 10;
Vector3[] ZombieLoc(TotalZombies);
Quaternion[] OldRot(TotalZombies);
void Main()
{
   if (iInitializing())
   {
      Vector3 q;
      for (int i=0; i<TotalZombies; i++)
      {
         iObjectScan(OBJ_0,Vector3(iFloatRand(-20,20),20,iFloatRand(-20,20)),Vector3(0,-20,0),0.00001,ZombieLoc[i],q);
      }

      OUT_44 = iFloatRand(0,2);
      OUT_66 = iFloatRand(0,2);
      OUT_88 = iFloatRand(0,2);
      OUT_110 = iFloatRand(0,2);
      OUT_132 = iFloatRand(0,2);
      OUT_154 = iFloatRand(0,2);
      OUT_176 = iFloatRand(0,2);
      OUT_198 = iFloatRand(0,2);
      OUT_220 = iFloatRand(0,2);
      OUT_242 = iFloatRand(0,2);
   }

   Vector3 PlayerLoc;
   iObjectLocation(OBJ_22,PlayerLoc);
   PlayerLoc.y -= 1.8;

   float[] Distance(TotalZombies), Speed(TotalZombies);

   Quaternion[] LookRot(TotalZombies);
   Vector3[] MoveLoc(TotalZombies), NewZombieLoc(TotalZombies);

   Vector3[] GroundLevelLoc(TotalZombies);
   Vector3 q;

   for (int i=0; i<TotalZombies; i++)
   {
      ///Get Distance & Speed
      Distance[i] = iVectorLength(PlayerLoc-ZombieLoc[i]);
      Speed[i] = -1/(80*(Distance[i]-2.0))+0.05;
      if (Speed[i] < 0 || Speed[i] > 0.05) Speed[i] = 0;

      ///Get Rotation & Movement
      iQuaternionLookAt(LookRot[i],(Vector3(PlayerLoc.x,0,PlayerLoc.z)-Vector3(ZombieLoc[i].x,0,ZombieLoc[i].z)),Vector3(0,1,0));
      iVectorRotate(MoveLoc[i],Vector3(0,0,Speed[i]),LookRot[i]);
      NewZombieLoc[i] = ZombieLoc[i]+MoveLoc[i];
      OldRot[i] = LookRot[i];

      ///Get Ground Level
      iObjectScan(OBJ_0,Vector3(NewZombieLoc[i].x,20,NewZombieLoc[i].z),Vector3(0,-20,0),0.00001,GroundLevelLoc[i],q);
      ZombieLoc[i] = GroundLevelLoc[i];
   }

   ///Set Location
   iObjectLocationSet(OBJ_44,GroundLevelLoc[0]);
   iObjectLocationSet(OBJ_66,GroundLevelLoc[1]);
   iObjectLocationSet(OBJ_88,GroundLevelLoc[2]);
   iObjectLocationSet(OBJ_110,GroundLevelLoc[3]);
   iObjectLocationSet(OBJ_132,GroundLevelLoc[4]);
   iObjectLocationSet(OBJ_154,GroundLevelLoc[5]);
   iObjectLocationSet(OBJ_176,GroundLevelLoc[6]);
   iObjectLocationSet(OBJ_198,GroundLevelLoc[7]);
   iObjectLocationSet(OBJ_220,GroundLevelLoc[8]);
   iObjectLocationSet(OBJ_242,GroundLevelLoc[9]);


   ///Set Rotation
   iObjectOrientationSet(OBJ_44,LookRot[0]);
   iObjectOrientationSet(OBJ_66,LookRot[1]);
   iObjectOrientationSet(OBJ_88,LookRot[2]);
   iObjectOrientationSet(OBJ_110,LookRot[3]);
   iObjectOrientationSet(OBJ_132,LookRot[4]);
   iObjectOrientationSet(OBJ_154,LookRot[5]);
   iObjectOrientationSet(OBJ_176,LookRot[6]);
   iObjectOrientationSet(OBJ_198,LookRot[7]);
   iObjectOrientationSet(OBJ_220,LookRot[8]);
   iObjectOrientationSet(OBJ_242,LookRot[9]);


   OUT_264 = iFrameRate(true);

///OBJ_0   = Terrain
///OBJ_22  = Player
///OBJ_44 - 242 = Zombie SkinMeshes
///OBJ_264 = Valueprint
}
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0

secondry2

« Reply #16 on: June 14, 2012, 05:44:18 PM »
thanks mate! appreciate it 8)

secondry2

« Reply #17 on: July 03, 2012, 06:14:34 PM »
Do you think if i did the same script, except placed spherical rigid bodies instead of the skin meshes (as a separate script to the skin meshes) and placed the spheres where the skin meshes are placed in the GUI editor, so theoretically, the rigid bodies are bound to the skinmeshes, then ill work out something to keep them together.

A lil complicated, but what do you think?
« Reply #18 on: July 05, 2012, 09:03:36 AM »
Not a good idea. I know it sounds all great in your head, but it doesn't work like that.
Well, yeah, you would get rigidbodies in the spots of the skinmeshes, but setting a location or orientation of an active and colliding rigidbody is not a good idea. Things might go crazy.
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0

secondry2

« Reply #19 on: July 05, 2012, 05:05:34 PM »
Lol, "things might go crazy". Happens a lot ;D. What, in your opinion, would be the best way, because ive been brainstorming and writing my ideas down, but thats the only way i am cabable of doing this  :-\
« Reply #20 on: July 06, 2012, 01:35:30 AM »
I have no idea.
It's sounds extremely complicated to me to make the script take account for all the other zombies, objects and the player.
This sounds like a Jestermon job!
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0

secondry2

« Reply #21 on: July 06, 2012, 02:04:33 AM »
I have no idea.
It's sounds extremely complicated to me to make the script take account for all the other zombies, objects and the player.
This sounds like a Jestermon job!
"Sounds like a Jestermon job" lol.
But, in theory, wouldnt the script be similar to that one? I will see if i can modify it, so the one script controls both skinmeshes, and rigidbody meshes. Well, at least it should be anyway ::)
Pages: 1 [2]