Пример #1
0
        private void _UpdateTransform()
        {
            Vector3 direction = _path.GetDirection(_currentIndex);

            transform.position = _path.positions[_currentIndex]
                                 + direction * _offset;

            Vector3 directionInterpolated = _GetInterpolatedDirection();

            transform.LookAt(
                worldPosition: transform.position + directionInterpolated,
                Vector3.up
                );
        }
Пример #2
0
        void Update()
        {
            RaycastHit hitInfo;

            Physics.Raycast(
                origin: transform.position + Vector3.up * 100,
                direction: Vector3.down,
                out hitInfo,
                maxDistance: 200,
                ~_layerMask
                );
            Vector3 position = hitInfo.point;

            _DrawPoint(position, Color.white);

            _UpdateSegmentIndex(position);

            Plane startPlane = _path.GetSegmentPlane(_segmentIndex);
            Plane endPlane   = _path.GetSegmentPlane(_segmentIndex + 1);

            var   direction = _path.GetDirection(_segmentIndex);
            var   ray = new Ray(position, direction);
            float startDistance, endDistance;

            startPlane.Raycast(ray, out startDistance);
            endPlane.Raycast(ray, out endDistance);
            // Debug.Assert(startDistance < 0);
            // Debug.Assert(endDistance > 0);
            startDistance = Mathf.Abs(startDistance);
            endDistance   = Mathf.Abs(endDistance);

            float offsetFactor = startDistance / (startDistance + endDistance);
            var   offsetLength = _path.GetSegmentLength(_segmentIndex) * offsetFactor;

            distance = _path.distances[_segmentIndex] + offsetLength;
        }