예제 #1
0
        private void OnTriggerStay2D(Collider2D collision)
        {
            if (!collision.attachedRigidbody)
            {
                return;
            }

            PerceiveUnit unit = collision.GetComponent <PerceiveUnit>();

            if (!unit)
            {
                return;
            }

            _noiseAccumulator += collision.attachedRigidbody.velocity.magnitude * walkVelocityScale;

            if (_noiseAccumulator > noiseThreshold && SenseNoise.CanSpreadNoise())
            {
                _noiseAccumulator = 0;

                NoiseData noiseData = new NoiseData();
                noiseData.position = collision.transform.position;
                noiseData.velocity = collision.attachedRigidbody.velocity;
                noiseData.fraction = unit.fraction;

                SenseNoise.SpreadNoise(noiseData);
            }
        }
예제 #2
0
        void ReactToNoise(NoiseData data)
        {
            if (data.fraction && myUnit.fraction.GetAttitude(data.fraction) != Fraction.EAttitude.EEnemy)
            {
                return;
            }

            Vector2 toNoise = (Vector2)transform.position - data.position;

            if (toNoise.sqrMagnitude > hearingDistance * hearingDistance || Random.value > reactionChance)
            {
                return;
            }

            MemoryEvent ev = new MemoryEvent();

            ev.velocity      = data.velocity * velocityPredictionScale;
            ev.forward       = data.velocity;
            ev.exactPosition = data.position;
            ev.lifetimeTimer.Restart();

            noiseStorage.PerceiveEvent(ev);

#if UNITY_EDITOR
            Debug.DrawRay(ev.exactPosition, Vector3.up, Color.blue, 0.5f);
#endif
        }
예제 #3
0
 public static void SpreadNoise(NoiseData data)
 {
     if (tSpreadNoise.IsReadyRestart())
     {
         onSpreadNoise(data);
     }
 }
예제 #4
0
        void Start()
        {
            var healthController = GetComponent <HealthController>();

            healthController.onDamageCallback += (DamageData data) =>
            {
                _damageAccumulator += data.damage;

                if (_damageAccumulator >= damageThreshold && SenseNoise.CanSpreadNoise())
                {
                    _damageAccumulator = 0;

                    NoiseData noiseData = new NoiseData();
                    noiseData.position = data.position;
                    noiseData.velocity = Vector2.zero;

                    SenseNoise.SpreadNoise(noiseData);
                }
            };
        }