- Home /
 
 
               Question by 
               OreoSplitter · Jul 12, 2018 at 03:48 PM · 
                c#raycasttransform  
              
 
              How do I move a raycast back on objects z axis?
Right now I'm just getting the transform of a child object because I couldn't figure this out. I want to use the transform of the current object script is on but first move it back a few units (along the objects Z axis) before using it.
     void Raycast()
     {
         if (current_Target != null)
         {
             transform.LookAt(current_Target.transform);
             Transform ray_Pos = transform.GetChild(0);
 
             RaycastHit hit;
 
             Ray ray = new Ray(ray_Pos.position, transform.forward);
 
             if (Physics.Raycast(ray, out hit, 2f, 1024))//layer Enemies
             {
                 Remove_Projectile();
             }
         }
     }
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Remy_Unity · Jul 13, 2018 at 07:45 AM
What about using :
 Ray ray = new Ray(transform.position - transform.forward * distance, transform.forward);
 
              Your answer
 
             Follow this Question
Related Questions
Drawing flat arrows 1 Answer
Help with casting a raycast C# 1 Answer
Place Gameobject within a specific tranform value 3d 3 Answers
Player using turret problem 1 Answer