- Home /
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 :)
It is unclear what your problem is here. You create a ray, but there is no Raycast() in the code you provide, so we cannot verify how you are finding your hit point. Also if you have multiple camera's in the scene, you need to create your ray using the specific camera the user is using to view the scene.
there is one camera. $$anonymous$$y question is not about hit point, question is why ray is not moving. I assigned with input.mouseposition, but it is like it doesnt respect to mouse input.
Answer by robertbu · Feb 22, 2014 at 05:01 PM
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.
I want to get like , if hits terrain get hit.point moveToPoint() which makes my character move to hit.point so I must able to hit that ray on where my mouse on the terrain.
thank you for help !! :))
Your answer
Follow this Question
Related Questions
Camera Movement issue 1 Answer
Need help with a mouse orbit script 1 Answer
Raycast Third Person Camera Problem 4 Answers
Unity Android Movement Problem 0 Answers
Touch mouseorbit 5 Answers