- Home /
Question by
orangebagel1213 · Mar 19 at 08:00 PM ·
mouse position
Follow Mouse 3D top down
Hi I have here a code wherein the player will follow my mouse using raycast but movement is stopped when i am not pointing on the ground (pointing on an object in the scene) I tried assigning them ignore raycast layer but it still wont work. Anyway this is my code I found it on a youtube tutorial.
if (Input.GetMouseButton(0))
{
ray = cam.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
if (hit.collider == groundCollider)
{
transform.position = Vector3.MoveTowards(transform.position, hit.point, Time.deltaTime * HoleMoveSpeed);
}
}
}
Comment