Ray camera to Terrain goes Wrong.

Hi guys , I tried to write a script that raycasting camera to terrain(name that point x) and player will move this point x.
I am using Orbit camera and i read something that raycasting to terrain with orbit camera is more complex than other camera types. also i am fully locked camera and I wrote code like this and it is worked but When i try to write code on orbit camera it is not worked.

Here is my ray code;

 void mouseToWorld(){

	RaycastHit hit;
	Vector3 mCoo = cam.ScreenToWorldPoint (Input.mousePosition);
	mRay = cam.ScreenPointToRay(mCoo);
	Debug.DrawRay (mRay.origin, mRay.direction*999, Color.yellow);


and here is the Screenshot that shows where ray is casting;
(annotation: when i hit play, ray cast is drawing but when i move the mouse , it doesnt move, it is locked to same position)

Thank you for helps :slight_smile:

The Issue is that you are passing a world point to the ScreenPointToRay() function. Change line 5:

mRay = cam.ScreenPointToRay(Input.mousePosition);

Note that even with this fix, you will not be able to see this ray in Game view because the camera will always be looking at the ray end-on.