Ejemplo n.º 1
0
        public void OnCollision(float force, Vector3 position, Vector3 normal, bool deform)
        {
            float product = Math.Abs(Vector3.Dot(Chassis.Actor.GlobalPose.Forward, normal));

            if (Chassis.LastSpeeds.GetMax() > 7)
            {
                int particles = Math.Min(8, (int)force / 150000);

                if (force > 50000)
                {
                    _vehicleBitsEmitter.DumpParticles(position, particles, Vector3.Zero);
                    GameConsole.WriteEvent("dump particles " + particles);
                }
                //else
                //    _vehicleBitsEmitter.Update(position);

                if (force > 400)
                {
                    GameVars.SparksEmitter.DumpParticles(position, 6, Vector3.Zero);
                }

                if (Driver is PlayerDriver)
                {
                    if (product < 0.3f)
                    {
                        SoundCache.PlayScrape(this);
                    }
                    else if (force > 50)
                    {
                        SoundCache.PlayCrash(this, force);
                    }
                }
            }
            if (deform && _deformableModel != null)
            {
                _deformableModel.OnContact(position, force, normal);
            }

            // if this is a CPU driven car, only damage if the player has something to do with it.  Stops cars killing themselves
            if (Driver is CpuDriver && ((CpuDriver)Driver).LastPlayerTouchTime + 0.3f > Engine.TotalSeconds)
            {
                Damage(force, position);
            }
            else if (Driver is PlayerDriver)
            {
                Damage(force, position);
            }
        }