Raycasting backwards problem?

I have some raycasting on my rigidbody player. I have looked around on it, as i am new on raycasting, and it says that the value -Vector3.forward is for backwards. Well for me it doesn’t seem to raycast backwards. If i use Vector3.forward, then it shoots rays forwards. But if i then use -Vector3.forward and Vector3.forward both then none of the raycasting works. Below is my code

void RayCastingShoot(Vector3 direction)
	{
		if (Physics.Raycast (transform.position, direction, 0.5f)) 
		{
			playerSpeed = 0.0f;
		} else {
			playerSpeed = 2.0f;
		}

		if(Physics.Raycast(transform.position, -Vector3.up, out hit))
		{
			distanceToGround = hit.distance;
		}
		if(distanceToGround <= 0.1)
		{
			Grounded = true;
		}
		Debug.DrawLine (transform.position, direction, Color.cyan);
	}


	void FixedUpdate()
	{

		RayCastingShoot (-Vector3.forward);
		RayCastingShoot (Vector3.forward);

	        //Some code down here related only to animation and movement. Not raycast
		}

I test to see if it is casting backwards, by walking my player backwards into a box collider object. It doesn’t stop moving. Just carries on. Help me, the faithful community :smiley:

I’m guessing you want the forward and backward of the object, not the world forward and back. If so, replace ‘Vector3.forward’ with transform.forward. Replace ‘-Vector3.forward’ with ‘-transform.forward’.

Note if you really want world directions, there is a Vector3.back (but transform.back does not exist).