//Code written by Luis Quinones @ [complicitMatter]
//Feel free to use and modify the code in any way you want, please comment below with suggestions, ideas of any relevant throughts
private void RunScript(Point3d att, bool reset, int ptCount, ref object A)
{
BoundingBox bb = new BoundingBox(-100, -100, -100, 100, 100, 100); //set bounding box
Random rnd = new Random();
List<Vector3d> vecs = new List<Vector3d>();
List<Point3d> returnedvecs = new List<Point3d>();
if(reset){ //reset will re initialize all values, since we are using the timer we will use this as a trigger
this.startList = new List<Vector3d>();
for(int i = 0; i < ptCount; i++){
this.startPos = new Vector3d(rnd.Next(-100, 100), rnd.Next(-100, 100), rnd.Next(-100, 100)); //set the starting position
this.startList.Add(this.startPos);
this.moveVec = new Vector3d(rnd.NextDouble(), rnd.NextDouble(), rnd.NextDouble()); //set the move vec
int switchDir = rnd.Next(-1, 1); //use trigger to make some random values negative doubles
if(switchDir < 0){
this.moveVec *= 2;
}else{
this.moveVec *= -2;
}
this.moveList.Add(this.moveVec);
}
creeperPoints = this.startList;
}else{
creepers creeperPts = new creepers(this.startList, this.moveList, bb); //create instance of creepers
creeperPts.move();
this.startList = creeperPts.outputList;
creeperPoints = this.startList;
}
}
//------------Global Variables--------------------
private List<Vector3d> moveList = new List<Vector3d>();
private List<Vector3d> startList = new List<Vector3d>();
private Vector3d startPos = new Vector3d();
private Vector3d moveVec;
//------------Creeper Class Agents------------------
public class creepers{
//---------------Class Variables--------------------
private BoundingBox bbox;
public Vector3d pos = new Vector3d();
public List<Vector3d> posList = new List<Vector3d>();
public List<Vector3d> posMoveList = new List<Vector3d>();
public List<Vector3d> outputList = new List<Vector3d>();
//-----------------Constructor----------------------
public creepers(List<Vector3d> vecs, List<Vector3d> move, BoundingBox bb){
this.posList = vecs;
this.posMoveList = move;
this.bbox = bb;
}
//-----------------Move method----------------------
public void move(){
for(int i = 0; i < this.posList.Count; i++){
this.pos = new Vector3d();
this.pos += this.posList[i];
this.pos += this.posMoveList[i];
this.checkLoc();
this.outputList.Add(this.pos);
}
}
//------------Check location method----------------
//if the creeper is past the bounding box then spawn in a new location inside
public void checkLoc(){
if(!this.bbox.Contains((Point3d) this.pos)){
Random rnd = new Random();
this.pos = new Vector3d(rnd.Next(-100, 100), rnd.Next(-100, 100), rnd.Next(-100, 100));
}
}
}
Update