RayCast From Centre of Camera

Hey all,

I’m trying to make a RayCast from the centre of my camera, but it’s not working properly- it only works if I’m facing a certain direction. My code so far is:

	void FixedUpdate() {
		RaycastHit hit;
		Ray forwardRay = new Ray (player.transform.position, Vector3.forward);

		if (Physics.Raycast (forwardRay, out hit, sightDistance)) {
		//more code

What’s going wrong? Thanks so much!


When defining the ray, change the direction from;




Otherwise, you are just accessing a constant direction, in this case the world’s Z axiz, rather than the Z axis of your object.