- Home /
 
               Question by 
               LostSoul_Gaming · Apr 19, 2017 at 10:09 AM · 
                movementraycastspawnmove an objectdistance check  
              
 
              Set distance away from an object
So I have a ring of cubes that spawn in the center of a tube. The idea is that each cube fires a raycast towards a second ring of cubes, the 2nd ring is larger and outside the tube. I want to find the distance from the tube walls and move each cube to within X meters of the wall. I can find the distance but im not sure how to go about moving the cubes where i want them to be 
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class TestStuf : MonoBehaviour {
 
     RaycastHit hit;
     public GameObject target;
     float distance;
     // Update is called once per frame
     void Update () {
         Debug.DrawRay(this.transform.position, target.transform.localPosition);
 
             if (Physics.Raycast(this.transform.position,target.transform.position, out hit)){
             distance = hit.distance;
             print(distance + " from " + hit.collider.gameObject.name);
 
         
         }
 
         
     }
 }
 
 
                 
                rings.png 
                (296.6 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                