Quantcast
Channel: Latest Questions by hardmode2236
Viewing all articles
Browse latest Browse all 112

JS access spherecast position

$
0
0
In this 2d concept im trying to make a bacteria colony produce spores. So i make it look in a random direction around itself and if it casts a sphere in that direction without hitting any other spores, then it grows a spore there. But, im not sure how to re-access the spherecast's position once iv used it. here is my code: #pragma strict var growthCount = 0; var growthCountMax: int; var newSpore: GameObject; var randomDir: Vector3; var hit: RaycastHit; var spawnDistMaster: float; var spawnDist: float; var spawnDistNoise: float; var newSporePos: Vector3; function Start () { } function Update () { } function incGrowthCount(num:int) { growthCount = num-1; } function lookForGrowSpot() { spawnDist = spawnDistMaster + Random.Range(-spawnDistNoise, spawnDistNoise); randomDir = Vector3(Random.Range(-359,359),0,Random.Range(-359,359)); Debug.DrawRay(transform.position, randomDir, Color.cyan); if(!Physics.SphereCast(transform.position, .3, randomDir, hit, spawnDist)) { Debug.Log("Hit Nothing"); //store the spherecasts ending position in "newSporePos" //newSporePos = ?; grow(); return true; } Debug.Log("hit somthing"); return false; } function grow() { //make spore at newSporePos } also as a bonus question: is there a better way to make a random direction in 2d than what i did? what i have now just feels wrong.

Viewing all articles
Browse latest Browse all 112

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>