Пример #1
0
        public void UpdateAgent(SteeringAgent _agent)
        {
            Vector3 force = Calculate(_agent).normalized;

            _agent.UpdateCurrentForce(force);

            Quaternion rotation = Quaternion.Slerp(_agent.Rotation, Quaternion.LookRotation(_agent.CurrentForce != Vector3.zero ? _agent.CurrentForce : Vector3.one), Time.deltaTime);
            Vector3    movement = (_agent.Forward + force * _agent.Speed) * Time.deltaTime;
            Vector3    position = Vector3.SmoothDamp(_agent.Position, movement + _agent.Position, ref _agent.velocity, _agent.MovementSmoothing);

            _agent.SetPosandRot(position, rotation);
        }
        /// <summary>
        /// Runs the calculations for the position and rotations of the passed
        /// agents using the force calculated in the <see cref="Calculate(SteeringAgent)"/> function
        /// </summary>
        /// <param name="_agent"></param>
        public void UpdateAgent(SteeringAgent _agent)
        {
            Vector3 force = Calculate(_agent).normalized;

            _agent.UpdateCurrentForce(force);

            // Calculate the rotation using Slerp, the current roation and the force for the target
            Quaternion rotation = Quaternion.Slerp(
                _agent.Rotation,
                Quaternion.LookRotation(_agent.CurrentForce != Vector3.zero ? _agent.CurrentForce : _agent.Forward),
                Time.deltaTime * 10f);

            // Calculate the position by finding the correcting movement then damping the difference.
            Vector3 movement = (_agent.Forward + force * _agent.Speed) * Time.deltaTime;
            Vector3 position = Vector3.SmoothDamp(
                _agent.Position,
                movement + _agent.Position,
                ref _agent.velocity,
                _agent.MovementSmoothing);

            // Apply the calculated rotation and position
            _agent.ApplyPosandRot(position, rotation);
        }