I Want To Move Character To Where My Mouse Is Using Invisible Plane So it Doesn’t Go Up Wall
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseController : MonoBehaviour
{
public Camera camera;
// Update is called once per frame
void Update()
{
Ray cameraRay = camera.ScreenPointToRay(Input.mousePosition);
Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
float rayLength;
if(groundPlane.Raycast(cameraRay, out rayLength))
{
Vector3 hit = cameraRay.GetPoint(rayLength);
Debug.DrawLine(cameraRay.origin, hit, Color.blue);
transform.Translate(hit.x, 0f, hit.z);
}
}
}