Quantcast
Channel: Answers by "Peter G"
Viewing all articles
Browse latest Browse all 90

Answer by Peter G

$
0
0
Moving a character to a point is the same process as moving value to a destination. You find the direction then move in that direction until the offset is less than a specified precision. void Update () { //Given some means of determining a target point. var targetPoint = FindTargetPoint(); //However you want to do that. MoveTowardsTarget (targetPoint); } void MoveTowardsTarget(Vector3 target) { var cc = GetComponent(); var offset = target - transform.position; //Get the difference. if(offset.magnitude > .1f) { //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; //normalize it and account for movement speed. cc.Move(offset * Time.deltaTime); //actually move the character. } }

Viewing all articles
Browse latest Browse all 90

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>