3rd Person Shooter Crosshair system
3rd Person Shooter
I am trying to make a 3rd person shooter, so the crosshair follows your mouseposition. This means I have to convert the mousePosition to a ScreenToWorldPoint. I want the crosshair to be like 2 above the ground. The thing is I am not looking at the object(ground) from above, I am looking at it oblique. Like this: link text
I've already tried:
Vector3 v3 = Input.mousePosition;
v3.z = 24.2f; (24.2f is the distance from the camera to the ground -2)
v3 = Camera.main.ScreenToWorldPoint(v3);
transform.position = v3;
But when using those lines the cursor will for example sometimes be 2 above the ground and sometimes like 4 above the ground because of the oblique view. Like this: link text
I was thinking about maybe Raycasting the every position and assign that value to the v3.z from the code above, but I have no clue on how to do this. Any other suggestions or a suggestion on how to do the above? All help would be very appreciated!
Answer by RaytjeKnOfficial · May 11, 2017 at 10:43 AM
I figured something out:
Vector3 aboveGround = new Vector3(0,.5f,-.3f);
Vector3 mousePos = Input.mousePosition;
Ray castPoint = Camera.main.ScreenPointToRay(mousePos);
RaycastHit hit;
if (Physics.Raycast(castPoint, out hit, Mathf.Infinity))
{
hit.point += aboveGround;
transform.position = hit.point;
}
Your answer
Follow this Question
Related Questions
2d Shooting to Mouse position 0 Answers
Circle crosshair that fits the bullet spread 1 Answer
Screen to World Point on 2.5D game 0 Answers
am trying to instantiate a 3D object to fly in the direction where my mouse is pointing 0 Answers
Object is stuck at center of camera instead of following mouse 2 Answers