Inaccurate raycast help

Hello
I am trying to cast a ray from the camera to the information I get from a trigger stay but the ray does not travel to the centre of the object and the more dramatic the viewing angle the worse the error.What am I doing wrong here?.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class octrig : MonoBehaviour
{
    
    void OnTriggerStay(Collider other)
   {
    
           RaycastHit hit;
            
        if (Physics.Raycast(transform.position,other.transform.position, out hit, 333333))
  
        {
Debug.DrawRay(transform.position, other.transform.position * 333333, Color.yellow);

            Debug.Log("Did Hit");
           }
        else
        {
       
           Debug.DrawRay(transform.position, other.transform.position *333333, Color.yellow);
             Debug.Log("missed");
        }

When you look at the documentation of Draw Ray it will tell you the second parameter is a direction. SO probably something like

Debug.DrawRay(transform.position, (other.transform.position - transform.position) * 333333, Color.yellow);

should work better.

Also, if you want to detect what’s hit in a line-segment i.e. between two points in the world then use Physics.Linecast.

Thanks guys that did it was driving me nuts would probably never have figured that out