- Home /
Raycast collision issue
Hi everyone,
I'm playing around with raycasts and was wondering why my script isn't working. It's set up to detect objects with a tag(chose EditorOnly randomly). If it hits an object with that tag it draws a green line in the scene view. It looked like it was working but then I noticed that the rays seems to be offset by some amount. Its like the collider is shifted. Here's some images to show what I mean.


I have the below script tied to the main camera of the Unity RigidBodyFPSController. Does anyone know what I'm doing wrong and what I need to change to correct this issue?
Thanks
using UnityEngine; using System.Collections;
 public class Raycast : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         RaycastHit hit;
 
         Vector3 fwd = transform.TransformDirection(Vector3.forward);
         
         if (Physics.Raycast(transform.position, transform.forward, out hit, 20.0f))
         {
             if (hit.collider.gameObject.tag.Equals("EditorOnly"))
             {
                 Debug.DrawLine(transform.position, fwd * 10, Color.green, 20, true);
                 print(hit.collider.gameObject.name);
                 print(hit.point);
             }
         }    
     }
 }
Add Debug.DrawRay to better show the Raycast, not a linecast
Your answer
 
 
             Follow this Question
Related Questions
Problem With Raycasthit Angle 0 Answers
Something fishy with RaycastHit 1 Answer
Rays do not detect terrain and prefabs do not spawn where wanted 1 Answer
How can I can I cast a ray from a gameobject? 1 Answer
Raycast Not Working 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                