c# Raycast going off at odd angles. Unity 5

I can’t get a hit on my game object when I am standing in the red debug laser, but if I move to the left, far from the debug draw line, I get a hit. This is vexing me :frowning:
I got angry and named EVERYTHING “PlayerCube,” but that did not fix anything.

using UnityEngine;
using System.Collections;

public class Sight : MonoBehaviour {
	public Transform ObjectEye;

	Vector3 playerPosition;
	Vector3 subjectPosition;
	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {

		Vector3 fwd = transform.TransformDirection(Vector3.forward);
		playerPosition = transform.position;
		subjectPosition = ObjectEye.position;
		RaycastHit hit;
		if (Physics.Raycast (transform.position, subjectPosition, out hit) && hit.transform.name == "PlayerCube") {
				Debug.LogError ("poke");


		Debug.DrawLine(transform.position, subjectPosition, Color.red);


Okey, so I finaly tested your code and it’s working fine, your Raycast is correct. From the beginning it wasn’t working but then I saw the rest of your Ccondition:

if (Physics.Raycast(...) && hit.transform.name == "PlayerCube")

So I’ve changed the name of my target Game Object to “PlayerCube” and sudenly it worked.

this Vector3 fwd = transform.TransformDirection(Vector3.forward); should be Vector3 fwd = transform.TransformDirection(transform.forward); and then use if (Physics.Raycast (transform.position, fwd , out hit,1000f) && hit.collider.transform.name == "PlayerCube") { //something done here } Debug.DrawRay(StartPos, fwd, Color);