Example #1
0
    void OnCollisionEnter(Collision other)
    {
        Vector3 impact = (other.contacts[0].point) - transform.position;

        if (_ImpactEvents.Count < m_MaxNumberOfImpacts)
        {
            if (m_RippleEffect != null)
            {
                GameObject shell = (GameObject)Instantiate(m_RippleEffect, transform.position, Quaternion.identity);
                shell.transform.LookAt(impact + transform.position);
                Vector3 offset = shell.transform.position;
                offset.z += Random.Range(-1f, 1f) / 100;
                //shell.transform.position = offset;
                //shell.transform.localScale = transform.localScale;
                shell.transform.parent     = transform;
                shell.transform.localScale = Vector3.one * 0.95f;

                ImpactEvent newEvent = new ImpactEvent();
                newEvent.RippleEffect = shell;
                newEvent.pos          = transform.position + impact * 3;
                newEvent.material     = shell.GetComponent <Renderer>().material;
                newEvent.material.SetVector("_ImpactPos", new Vector4(newEvent.pos.x, newEvent.pos.y, newEvent.pos.z));

                newEvent.offset.x = 2;

                _ImpactEvents.Add(newEvent);
            }
        }
        else
        {
            // Maximum number of Ripple effect objects reached, re-using one of the existing ones
            float lowest = 10.0f;
            int   index  = -1;

            for (int i = 0; i < _ImpactEvents.Count; i++)
            {
                if (_ImpactEvents[i].offset.x < lowest)
                {
                    lowest = _ImpactEvents[i].offset.x;
                    index  = i;
                }
            }

            _ImpactEvents[index].RippleEffect.transform.LookAt(impact);
            _ImpactEvents[index].pos = transform.position + impact * 3;
            _ImpactEvents[index].material.SetVector("_ImpactPos", new Vector4(
                                                        _ImpactEvents[index].pos.x,
                                                        _ImpactEvents[index].pos.y,
                                                        _ImpactEvents[index].pos.z));
            _ImpactEvents[index].offset.x = 2;
        }
    }
Example #2
0
 public void ShakeOnDiscreteImpact(ImpactEvent evt, SingleNode <ImpactCameraShakerConfigComponent> weapon, SelfTankNode tank, [JoinAll] CameraShakerNode cameraShaker, [JoinAll] SingleNode <GameCameraShakerSettingsComponent> settings, [JoinAll] SingleNode <MainHUDComponent> hud)
 {
     cameraShaker.cameraShaker.ShakeByDiscreteImpact(settings.component, weapon.component, evt.Force.normalized, evt.WeakeningCoeff);
     hud.component.battleHudRoot.ShakeHUDOnImpact(settings.component, weapon.component);
 }
Example #3
0
        private void ApplyInput(GameState s, float dt, ImpactEvent e)
        {
            Point p = HashHelper.Hash(e.Position, s.IGrid.numCells, s.IGrid.size);

            s.IGrid.Region[p.X, p.Y].AddToRegionImpact(e.ChangeAmount);
        }