Search Unity

My tower follows the mouse, but keeps shooting up towards the camera?

Discussion in 'Physics' started by Ben555, Jun 14, 2019.

  1. Ben555

    Ben555

    Joined:
    May 22, 2019
    Posts:
    13
    I tried to use a Layer Mask on just the Terrain so it wouldn't collide with anything else.

    if (hasBeenPlaced == false)
    {
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

    RaycastHit hit;

    if (Physics.Raycast(ray, out hit, myMask))
    {
    transform.position = hit.point;
    }
    }
    else
    {
    Destroy(this);
    }

    if (Input.GetMouseButtonDown(0))
    {
    hasBeenPlaced = true;
    }
     
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Probably the ray is hitting the tower each time it's moved.