ray from 2d image to 3d objects !!!!!


a 2d image is on my scene ( move with finger touch around the scene ) . this image is child of a canvas with “Screen Space-Overaly” render mode << important !!!

i want to know how can i get a ray from this 2d image to 3d objects !!!

i attach a image that make my question clear :slight_smile:



I think the problem is you think that raycasts have to come from cameras. They don’t. There’s a special, complicated raycast that shoots from the camera through the mouse. You may have seen that. But most raycasts are easier than that.

You should be able to find examples with “unity raycast down.” Lots of people want to check how far their player’s feet are from the ground, so do a down raycast from the player.

A basic down raycast looks like this:

RaycastHit Hit;
if(Physics.Raycast(transform.position, Vector3.down, out Hit, 10)) {
  Debug.Log("I am over "+Hit.transform.name);

Looks odd, but transform.position says to start from where you are, and Down says to fire it down. If your game is on a wall, then shoot it forward instead (whichever direction the thing under you will be.) Then Hit catches info about what you hit, and 10 is distance to shoot (using Hit requires you to use distance, just because. Can put 9999.)

You should be able to find lots of raycast examples of this general form. Yes, they are tricky.