i want to move an object on the x axis to a specific point where i right click my mouse would i do this with raycasting?
you need to raycast from the camera to the mouse, then add a check for mouse click in an if statement. Then, change the object’s x position to the x position of the hit.
Use raycast to find where the user clicked, Then create a new Vector3 where “x = raycast.hit.x” and keep y and z the same as your characters y and z, Then use NavMesh to move the object to the Vector3 you created.
from : Unity - Scripting API: Physics.Raycast
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
void Update()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100))
Debug.DrawLine(ray.origin, hit.point);
}
}
you can use the parameters on hit.point
to determine your position to move to