예제 #1
0
        void UpdateModifier(SeekMotionModifierComponent modifier, ref Vector3 velocity, Vector3 position, float deltaTime)
        {
            if (!modifier.Target.HasTarget)
            {
                return;
            }

            var   difference = modifier.Target.Target - position;
            float distance   = difference.magnitude;

            if (distance > modifier.PerceptionDistance || distance < modifier.StopDistance)
            {
                return;
            }

            var   direction = difference.normalized;
            float strength  = modifier.Strength;

            if (distance <= modifier.SlowDistance)
            {
                strength *= (distance - modifier.StopDistance) / (modifier.SlowDistance - modifier.StopDistance);
            }
            else if (distance <= modifier.StopDistance)
            {
                strength = 0f;
            }

            velocity += direction * strength * deltaTime;
        }
예제 #2
0
        void UpdateModifier(SeekMotionModifierComponent modifier, ref Vector3 velocity, Vector3 position, float deltaTime)
        {
            if (!modifier.Target.HasTarget)
                return;

            var difference = modifier.Target.Target - position;
            float distance = difference.magnitude;

            if (distance > modifier.PerceptionDistance || distance < modifier.StopDistance)
                return;

            var direction = difference.normalized;
            float strength = modifier.Strength;

            if (distance <= modifier.SlowDistance)
                strength *= (distance - modifier.StopDistance) / (modifier.SlowDistance - modifier.StopDistance);
            else if (distance <= modifier.StopDistance)
                strength = 0f;

            velocity += direction * strength * deltaTime;
        }