Need Help Converting 3d Raycast Into a 2D Raycast

Ok, I have been needing a lot of help especially sense Unity 4.3 came out, and sense that happened I need help converting my 3d ray cast into a 2d ray cast, I’ve checked out the scripting reference but however its not telling me how, unity is still complaining that I vector3 variables, how can i fix this f -

		var trans : Vector2 = new Vector2(transform.position.x, transform.position.y);
		var hit : RaycastHit2D;
		var fwd = transform.TransformDirection(Vector2.right);

and than Unity Recives this “No appropriate version of ‘UnityEngine.Physics2D.Raycast’ for the argument list ‘(UnityEngine.Vector2, UnityEngine.Vector3, UnityEngine.RaycastHit2D, int)’ was found.”

Im still receiving errors and i assume its with the fwd line.

You can’t use transform.position as this is an Vector3.

You need to convert it to Vector2 somehow - this of course depends on how your scene is setup, maybe like this:

Vector2 trans = new Vector2(transform.position.x, transform.position.y);

Hi Frostbite23,

I believe your issue is you’re trying to use Physics2D.Raycast the same way as Physics.Raycast.

In your last line: if(Physics2D.Raycast(trans,fwd,hit,range)){

You need to remove ‘hit’.

The new Physics2D only accepts ‘origin, direction, distance, layerMask, minDepth & maxDepth’