how to raycast towards the local -y direction of a game object?

Hi, im trying to raycast towards local -y direction of a game object that rotates on its z axis, but it seems like im getting only the global values. heres the script:

function Update () 
	{	
	var hit : RaycastHit;    
    
  	if(flip_button.flip==1){   //if button is pressed
  	
  	if (Physics.Raycast (transform.position, -Vector3.up, hit,100))
       			
       			{
				
				if (hit.collider.name == "walking_surface") 
					
					{	
					Debug.Log(hit.point.x);
					Debug.Log(hit.point.y);
					Debug.Log("HIT");
    				        flip_button.flip = 0;
					}          
				
				}
       		}
}

[16586-screen+shot+2013-10-16+at+12.20.00+pm.png|16586]

in the above image, the question mark thing is the “walking surface”, the clown is the game object from which raycast is to be done. the clown moves all over the surface of the “walking surface”. (in 2D)

please help

To answer your specific question, you want to use -transform.up as your direction. This is the local down converted into a world vector:

if (Physics.Raycast (transform.position, -transform.up, hit,100))

As a side note, what you are trying can be a hard problem. The issue is that when you align the cyclist with the normal of the surface, there will be times when the character is moved to his local forward resulting in the bottom not facing the mesh. If the bottom is not facing the mesh, then the raycast fails. Without a raycast the character either fails to move or moves off into space depending on how you’ve constructed your code.

I think that you will find what you need in Transform :smiley: