0

how can I change the Mathf.Infinity to make the Raycast length be something like 0.1 Meters?

// Fire a ray through the scene at the mouse position and place the target where it hits
RaycastHit hit;
if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, mask)) {
    newPosition = hit.point;
    positionFound = true;
}

Thanks for any help.

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
Gregger
  • 3
  • 1
  • Instead of trying to change Mathf.Infinity itself, the more sensible solution here should be changing the `... out hit, Mathf.Infinity ...` into `... out hit, 0.1f ...`. – Xiang Wei Huang Jul 12 '22 at 09:21
  • Then you'll need to set the `maxDistance` bigger. Maybe take an example on your game map, like a point and a mouse position that you know should trigger this behaviour. Then Debug.Log the point and the mouse position `Vector3`s, check their actual positions and see what number should you set as distance. – Xiang Wei Huang Jul 12 '22 at 09:46

0 Answers0