I’ve tried everything, searched everywhere, and can’t seem to get this working. I need a script in C# that moves an instantiated object towards the mouse position without using physics. EVery example I can find uses physics and I’d really prefer to avoid using them as much as possible. Can anyone give me a basic example of how to do this to get me started?
Start from this?
float speed = 0.01f;
float distance = 0;
Vector3 mousePos;
void Update () {
if (Input.getMouseButtonUp(0)) {
mousePos = GetMousePosHit();
}
if (distance >= 1) {
distance = 1;
return;
}
Vector3 newPos = Vector3.Lerp(transform.position, mousePos, distance);
distance+= speed;
}
void GetMousePosHit () {
Raycast ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, hit))
{
return hit.point;
}