// Update is called once per frame void Update() { framecount++; if (framecount % spawnInterval != 0 || count >= spawnLimit) { return; } Random.seed = (int)(Time.deltaTime * 1000); Vector3 pos = new Vector3(), normal = new Vector3(); if (vxe.RayCast(camera.transform.position, camera.transform.forward, 64, ref pos, ref normal)) { Vec3Int chunkcoord = vxe.ToGrid(pos) / vxe.chunk_size; BIOMES mybiome = biome.biomeMap[chunkcoord.x, chunkcoord.z]; int animal = Random.Range(0, spawns[(int)mybiome].obj.Length); GameObject spawnObject = spawns[(int)mybiome].obj[animal]; if (spawns[(int)mybiome].sticksToWalls[animal] || Vector3.Dot(normal, Vector3.up) > 0.999f) { GameObject newsphere = (GameObject)Instantiate(spawnObject, pos + normal * VoxelExtractionPointCloud.Instance.voxel_size * 0.5f, Quaternion.identity); newsphere.SetActive(true); //newsphere.GetComponent<GrowScript>().init(pos, normal, (Vector3.Dot (normal,Vector3.up) > 0.999f) ); count++; } } }
bool checkForJumpPositions(Vector3 dir, out Vector3 out_minAngleDir) { Vec3Int jumpCoords = vxe.ToGrid(transform.position); bool canJump = false; float maxdotprod = float.MinValue; Vector3 minAngleDir = Vector3.zero; for (int i = -JUMP_RANGE; i <= JUMP_RANGE; i++) { for (int j = -JUMP_RANGE; j <= JUMP_RANGE; j++) { for (int k = MAX_JUMP_HEIGHT; k >= 1; k--) { Vec3Int vcoords = jumpCoords + new Vec3Int(i, k, j); Voxel vx = vxe.grid.getVoxel(vcoords); if (vx.isOccupied() && vxe.voxelHasSurface(vx, VF.VX_TOP_SHOWN)) { Vector3 wrldcoords = vxe.FromGridUnTrunc(vcoords.ToVec3() + new Vector3(0.5f, 1.0f, 0.5f)); Vector3 vdir = Vector3.ProjectOnPlane((wrldcoords - transform.position), Vector3.up).normalized; float dotprod = Vector3.Dot(dir, vdir); if (dotprod > 0) { canJump = true; if (dotprod > maxdotprod) { maxdotprod = dotprod; minAngleDir = vdir; jumpPosition = wrldcoords; } } } } } } out_minAngleDir = minAngleDir; return(canJump); }
// Update is called once per frame void Update() { framecount++; if (spawned || framecount % spawnInterval != 0) { return; } Vector3 pos = new Vector3(), normal = new Vector3(); if (vxe.RayCast(camera.transform.position, camera.transform.forward, 64, ref pos, ref normal)) { Vec3Int chunkcoord = vxe.ToGrid(pos) / vxe.chunk_size; if (Vector3.Dot(normal, Vector3.up) > 0.999f) { GameObject newsphere = (GameObject)Instantiate(pet, pos + normal * VoxelExtractionPointCloud.Instance.voxel_size * 0.5f, Quaternion.identity); newsphere.SetActive(true); spawned = true; } } }
// Update is called once per frame void Update() { framecount++; // if ((framecount % 10 != 0 || (thingsSpawned.Count > maxToSpawnInBiome * 4)) && portal.activeInHierarchy) { return; } Random.seed = (int)(Time.deltaTime * 1000); //A Random Point in your Camera View Port Vector3 ranPt = new Vector3(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), backCam.nearClipPlane); //The World Point you see thru camera Vector3 startpt = backCam.ViewportToWorldPoint(ranPt); //The Direction vector from Camera to start point Vector3 dir = startpt - backCam.transform.position; Vector3 pos = new Vector3(), normal = new Vector3(); if (vxe.RayCast(startpt, dir, 64, ref pos, ref normal)) { //SPAWN PORTAL:********************************************************************* //If the portal is not active, try spawning one if (!portal.activeInHierarchy) { spawnPortal(pos, 0.6f, chunkFloorPos.y); } ///SPAWNING FOR ANIMALS********************************************************************* //Convert the voxel position into a Chunk World Position Vec3Int chunkcoord = vxe.ToGrid(pos) / vxe.chunk_size; //Loads up the BiomeMap through the grid size BIOMES mybiome = biome.biomeMap [chunkcoord.x, chunkcoord.z]; //If there are too many spawns in this Biome, do not spawn more if (spawnCountInBoime [(int)mybiome] > maxToSpawnInBiome) { return; } //randomly chooses an animal to spawn int animalIndex = Random.Range(0, spawnTable [mybiome].SpawnList.Length); GameObject spawnObject = spawnTable [mybiome].SpawnList [animalIndex].gameObject; Chunks chunk = vxe.getChunkFromPt(pos); bool isSurface = vxe.isChunkASurface(DIR.DIR_UP, chunk, .65f); if (spawnTable [mybiome].SpawnList [animalIndex].sticksToWalls || isSurface) // Vector3.Dot (normal, Vector3.up) > 0.999f) { { GameObject newsphere = (GameObject)Instantiate(spawnObject, pos + normal * VoxelExtractionPointCloud.Instance.voxel_size * 0.5f, Quaternion.identity); newsphere.SetActive(true); //SimpleAI ai = newsphere.GetComponent<SimpleAI> (); thingsSpawned.Add(newsphere); //newsphere.GetComponent<GrowScript>().init(pos, normal, (Vector3.Dot (normal,Vector3.up) > 0.999f) ); spawnCountInBoime [(int)mybiome]++; } } }