Visualizing raycasting [SOLVED]

First let me apologize for not having my code with me.

With that out of the way, perhaps I can get some pointers on how to achieve this.

What I want to do is cast a ray from my firing location, and then draw a debugging line from the fire location to the point that the ray hits the collider.

With all my various tests, it looks like the hit location isn’t on a straight line from the fire location to where the mouse clicked.

I think part of the problem may stem from the orientation of the fire location. I created an empty GO and parented it to the hand bone of my character. I then rotated the game object so that it’s local pos Z axis is pointing in the correct direction.

I cast my ray from the location of the GO and along it’s forward axis, but as I said, the hit location doesn’t look at all correct.

I will put together a test scene, and see if I can repeat the issue, but I am looking for any input on how to accomplish this. I am looking to do a 2d sprite game, so the raycast needs to only be in the world XY axis. All my objects are on Z = 0.

How would you go about it? Do I need to convert the mouse click location from screen space into world space? Do I need to orient my scene such that the axes I am working in are the world YZ, and all my objects are at X = 0, thus insuring that my rays are by default oriented correctly?

Any pointers to threads that will be of service will work as well.

This thread doesn’t really have anything to do with raycasting, but an example project was mistakenly posted to it. You’re right, though - there is a little bit of a trick in converting screen points to world space.

Thanks Andeee! That project helped me figure it all out.