Hey guys, im working on a game. I have and object (ball) rolling on a platform forwardly with its own speed and through the rings. All i want is when i click on right side of screen, move the ball to the right and same for left side. I did something closely but its not smooth and i guess im doing things wrong.
My code is
public class PlayerController : MonoBehaviour {
Vector3 targetPosition;
public float speed = 2f;
void Update ()
{
transform.Translate(0, 0, speed * Time.deltaTime);
if(Input.GetMouseButtonDown(0))
{
SetTargetPosition();
}
}
void SetTargetPosition()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 1000))
{
targetPosition = hit.point;
transform.LookAt(targetPosition);
}
}
Screenshot of project: