Question by
antonyellw · Jan 28, 2018 at 12:59 AM ·
c#cameraraycast
I can't get Physic.Raycast to work,My Physics.Raycast don't work
I'm trying to make the gameobject follow the mouse on a plane and i want to use the Physics.Raycast method, the cameraRayPosition always stays at 0, 0, 0 and i can't find anything that will solve my issue.
This is what iv'e wrote so far.
public Transform cameraTransform;
RaycastHit cameraRayHit;
Ray cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);
public Vector3 cameraRayPosition;
public Vector3 Show1;
// Use this for initialization
void Start ()
{
Show1 = cameraTransform.position;
}
// Update is called once per frame
void Update ()
{
if (Physics.Raycast(cameraTransform.position, Input.mousePosition, out cameraRayHit))
{
if(cameraRayHit.collider.tag == "Ground")
{
cameraRayPosition = cameraRayHit.point;
}
}
transform.position = cameraRayPosition;
}
Comment