character controller moves towards the object when that object is clicked but it does not go near that object , it stops according to the value set in moveSpeed variable…
please go through following code.
i want to move it to the object , i have set its magnitude point and it stops at specific distance. but if the object is far then i have to click more then one times to bring the character to the magnitude point.
void MoveTowardsTarget(Vector3 target) {
var cc = GetComponent<CharacterController>();
var offset = target - transform.position;
//target = transform.position(0,0,-distance)*moveSpeed;
//Get the difference.
if(offset.magnitude > 6.0f) {
transform.position = targetPosition;
// motor.desiredMovementDirection = Vector3.zero;
//If we're further away than .1 unit, move towards the target.
//The minimum allowable tolerance varies with the speed of the object and the framerate.
// 2 * tolerance must be >= moveSpeed / framerate or the object will jump right over the stop.
offset = offset.normalized * moveSpeed;
//offset = offset.normalized * moveSpeed - distance + target.position;
//normalize it and account for movement speed.
//offset = Vector3.MoveTowards(offset, target , moveSpeed);
cc.Move(offset * Time.deltaTime);
//actually move the character.
print ("in function");
}
}
in short the character controller covers the distance according to the value set in moveSpeed variable…it does not reaches to the objects’ magnitude point…!!
how can i make it reach to the object in one click.??