Raycast in the wrong way

Hello

Please i have a problem with my raycast, when i cast a ray, it didn’t follow the direction of my player, for exemple when i turn back my player, the ray continue to cast in back of it, it don’t turn with my player

I have wrote this line

 fwd = transform.TransformDirection(Vector3.forward);
	Debug.DrawRay(transform.position,fwd,Color.red);
		if ( Input.GetMouseButtonDown(0)) {
			RaycastHit hit;
			if (Physics.Raycast(transform.position, fwd,out hit)) {

here’s a picture to better understand

http://www.hostingpics.net/viewer.php?id=475857CastProblem.png

thank you

fwd = transform.TransformDirection(Vector3.forward); and transform.forward are the same thing.

Are you sure that script is attached to the transform performing the rotation or to one of it’s child ?

I guess your objects forward vector differs from your models facing? Just use fwd = -transform.forward; in that case.

@berenger the script is attached the root of my player, wich containt the camera the player, and other gameObject

@Lasse the problem is when i rotate too the ray doesn’t follow, not when i turn back only the ray stay at the same direction