I have a code which I also got from the internet. Here is the code:
var smooth:int; // Determines how quickly object moves towards position private var targetPosition:Vector3; function Update () { if(Input.GetKeyDown(KeyCode.Mouse0)) { var playerPlane = new Plane(Vector3.up, transform.position); var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hitdist = 0.0; if (playerPlane.Raycast (ray, hitdist)) { var targetPoint = ray.GetPoint(hitdist); targetPosition = ray.GetPoint(hitdist); var targetRotation = Quaternion.LookRotation(targetPoint - transform.position); transform.rotation = targetRotation; } } transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth); }
the problem with this code is that when I click to one place. my character is only facing to the place where I clicked and does not move there. do you know whats missing in this program? and also how will I be able to put the animation walk that after the character moved to the position it wil return to idle animation… thanks