When i add the highlighted code within the “raycast if loop” , the ray cast stops working [bcos in playmode i can see the character stops moving to the hitpoint destination on mouse click which other wise works fine.] Even if I add the highlighted code after the 'agent.destination=hitinfo.point; ’ same thing happens . Please help me out , as to why this is happening. Thanks in advance.
Has camera1 been set properly? Is the code throwing a null reference there?
In the ray setup you use “Camera.main” and inside the loop you use camera1… is that what you intend?
Assuming that Camera1 and camera.main are the same camera. I’m also assuming that when you say “the character stops moving to the hitpoint destination” that you mean the character is moving, but not moving to the position that you clicked. Never fiddled with changing camera settings in the same frame as making raycasts from it, but i imagine it could result in a few side effects.
My suspicion is:
You’re casting a ray from a point on the screen to world space. Then changing the camera FOV and perspective so that the point on the screen that was clicked no longer corresponds to the same position in world space that it did at the time the ray was cast. Giving the appearance that it is not moving to the point that was clicked, when it is.
Yes, exactly …you are spot on ! thats was indeed the problem. Somehow i left out the code to get the camera component from main camera. Thanks a lot bro , Am in complete awe at your skill:). God bless you.
thanks for the reply bro
I left out the get component here . my bad. ![]()
