Emirhan Soylu
Emirhan Soylu

Reputation: 40

Unity Raycasthit.Point Acting Weird

I'm trying to transport positions of a gameObject according to mouse position in 3D. However, When I do that with Raycasthit.point object is coming to player camera position like in this video

Is there anyone who can help me please

-> My Code:

 void Update()
    {
        if (currentObj != null)
        {
            currentObj.transform.position = MouseToWorldPositions();
        }
    }

    public Vector3 MouseToWorldPositions()
    {
        Ray ray = playerCam.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out RaycastHit hit, 999f, floorLayer))
        {
            return hit.point;
        }
        else
        {
            return Vector3.zero;
        }
    }

Upvotes: 0

Views: 487

Answers (1)

CodingGuy
CodingGuy

Reputation: 81

Are you sure your building blocks are not on the floorLayer mask? It seems that the raycast is hitting the edge of the building schematic and returning that point.

Upvotes: 1

Related Questions