Crosshair like in other third person games.

I’m currently experimenting with making third person games as I am a beginner programmer, I can’t get this to work correctly. I can set the crosshair to the mouse cursor position by doing Input.mousePosition, but I can’t stop it from “behaving like a cursor .” Like in most third person games, the crosshair is like above the player, and not directly in the center/right on the player, and it’s locked to it’s position.

Because if I lock the cursor to the center of the screen the ray cast shoots from the camera directly on the player, because it has a collider.

I wonder If I can use a layermask for this?
If anyone knows the game DayZ, you’ll see what I’m after.

Here is my code:

From my weapon script:

void ShootRay() {
        RaycastHit rayHit;

        Ray ray = MainCamera.ScreenPointToRay(Input.mousePosition);

        if(Physics.Raycast(ray, out rayHit, 100, maskEverything)) {


            Debug.DrawLine(ray.origin, rayHit.point, Color.green);

            Debug.Log(rayHit.transform.gameObject.name);

        }

    }

Cheers! :slight_smile:

1 Like

Hey, thanks for the reply. I’m gonna check this out. :slight_smile: