- Home /
Unity Waypoint Movement
So I'm making a game where you are a grenade trying to cross a road without getting hit by and cars. I want the movement to be wherever I tap the grenade starts rolling towards that position. I have tried addforce got nowhere with that, I tried movetowards hit.point but it just teleports and i tried vector3.lerp and it doesnt move. Heres my script: Ray ray; RaycastHit hit; public float speed; public Rigidbody rb; private void Update() { ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Input.GetMouseButtonDown(0)) { if (Physics.Raycast(ray, out hit, 200)) { transform.position = Vector3.MoveTowards(transform.position, hit.point, speed * Time.deltaTime); } } }
Comment