Hello friends, I’m trying to make my game object move from its current start position to where the user clicks on the screen. I’ve used a ScreenPointToRay to help find the position of where they click.
The basic problem I’m having is I’m unsure how to manipulate the Lerp function to smoothen out my movement. Right now, the game object is simply jumping to where the user clicks. Its not translating or moving, just appearing suddenly. I suspect the “t” variable of the Lerp function is something to do with it, but I don’t understand what it means. Any ideas? Thanks
function Update () {
var cube = GameObject.FindWithTag("Cube");
if(Input.GetMouseButtonDown(0)){
var startPos = cube.transform.position;
var ray : Ray = camera.main.ScreenPointToRay (Input.mousePosition);
var selected : RaycastHit;
Physics.Raycast(ray, selected);
cube.transform.position = Vector2.Lerp(startPos, selected.point, Time.time);
}
}