Is it normal that the raycast and drawline snaps to a single position?

Hi,

I am trying to attach a script to the player, where if he looks at an object an effect will happen.

So i attached this script:

var target : Transform;
var CanFollowTarget = false;
 
function Awake()
{
        target = GameObject.FindWithTag("Monster").transform;
}
 
function Update() {

// Positions
var hit: RaycastHit;
var forward = transform.TransformDirection (Vector3.forward);

// Left right
var leftR = transform.position;
var rightR = transform.position;

leftR.x -= 3;
rightR.x += 3;
 
 // Center raycast
    if (Physics.Raycast(transform.position, forward, hit))
    if(hit.collider.CompareTag("Monster"))
        {
                Debug.Log("INSANE");
                CanFollowTarget = false;  
                // Effect and sudden death should occur within seconds
        }
        else
        {
                CanFollowTarget = true;
        }
        
    // Left Raycast
 if(Physics.Raycast(leftR, forward, hit))
 if(hit.collider.CompareTag("Monster"))
 {
                Debug.Log("INSANE");
                CanFollowTarget = false;  
                // Effect and sudden death should occur within seconds
 }
 
 // Right Raycast
 if(Physics.Raycast(rightR, forward, hit))
 if(hit.collider.CompareTag("Monster"))
 {
                Debug.Log("INSANE");
                CanFollowTarget = false;  
                // Effect and sudden death should occur within seconds
 }
 Debug.DrawLine (transform.Position, hit.point);

}

At first it worked. But now, it looks like the raycast and the debug drawline. Snaps to a position.

I have to say that the camera is attached to an object. But the weird thing is, that when i first used the script it worked and now it doesn’t any more. The only thing i changed, was the left and right raycast.

Can anybody help me with this? Cause i can’t fix this.

Cheers,
Darryl

Okey so i got it. I fixed it with this:

var forward : Vector3 = transform.TransformDirection(Vector3.forward) * 100;

Instead of this:

var forward = transform.TransformDirection (Vector3.forward);

And as for the debugline, i used debug drawRay:

Debug.DrawRay (transform.position, forward, Color.green);

So that should be it.