Hello there,
I’m trying to translate a prefab to the point where mouse intersects a collider.
First, i get the coordinates the direction vector by ;
Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit mouseHit;
Physics.Raycast(mouseRay, out mouseHit);
float endXPoint = mouseHit.point.x;
float endYPoint = mouseHit.point.y;
float endZPoint = mouseHit.point.z;
returnVector = new Vector3(endXPoint, endYPoint, endZPoint);
Then,
i try to translate it by
transform.Translate(positionToFly*speedKoef);
//here positionToFly is the vector that has been calculated before.
I have 2 different origin points which activates these prefabs at the same time ( like dual guns ).
Now, when i start instantiate these prefabs, they arrive at different points!.
It’s like they have some sort of offset.
I think, the line
Camera.main.ScreenPointToRay(Input.mousePosition);
is causing the problem. Since this is not a FPS game, the camera sits at a different position than guns,so the ray which was drawn calculates a wrong direction ( with some sort of offset ) .
If this is the problem ,how can i solve this? How can i get mouspoint to ray without using Camera.main stuff?
If this is not the problem, how can i solve :p.
Thanks for the assistance.