Example #1
0
        private PathPosition closer(Vector3 from, PathPosition a, PathPosition b)
        {
            var distanceA = (from - a.getWorldPosition(this.rb.position.y)).sqrMagnitude;
            var distanceB = (from - b.getWorldPosition(this.rb.position.y)).sqrMagnitude;

            return((distanceA <= distanceB) ? a : b);
        }
Example #2
0
        void FixedUpdate()
        {
            var rbPosition = this.rb.position;

            this.previousPosition = this.closer(this.rb.position, this.pathPosition, this.previousPosition);
            this.pathPosition     = previousPosition + this.Speed * Time.fixedDeltaTime;
            var vectorPosition = this.pathPosition.getWorldPosition(this.rb.position.y);

            vectorPosition.y = rb.position.y;
            this.rb.MovePosition(vectorPosition);
        }
Example #3
0
 void Start()
 {
     this.pathPosition     = new PathPosition(this.StartNode);
     this.previousPosition = this.pathPosition;
     this.rb.position      = this.pathPosition.getWorldPosition(this.rb.position.y);
 }