// Not called on parts where physicalSignificance = false. Check the parent part instead.
        public void OnCollisionStay(Collision c)
        {
            if (!scrapeSparks || _paused)
            {
                return;
            }

#if DEBUG
            if (useSpheres)
            {
                spheres[3].GetComponent <Renderer>().enabled = true;
                spheres[3].transform.position = c.contacts[0].point;
            }
#endif
            foreach (ContactPoint contactPoint in c.contacts)
            {
                // Contact points are from the previous frame. Add the velocity to get the correct position.
                // Only the parent part has a rigidbody, so use it for all adjustments.
                Vector3 point = Utils.PointToCurrentFrame(contactPoint.point, part);

                Part foundPart = GetCollidingPart(contactPoint);
                if (foundPart != null)
                {
                    CollisionFX cfx = foundPart.GetComponent <CollisionFX>();
                    if (cfx != null)
                    {
                        cfx.Scrape(foundPart, c.gameObject, c.transform, point, c.relativeVelocity.magnitude, c.collider.name, (contactPoint.thisCollider is WheelCollider));
                    }
                }
            }
        }
 public void OnCrewEVA(GameEvents.FromToAction <Part, Part> action)
 {
     if (action.to.Modules["KerbalEVA"] != null)
     {
         CollisionFX cfx = action.to.AddModule("CollisionFX") as CollisionFX;
         cfx.scrapeSparks   = _scrapeSparks;
         cfx.collisionSound = _collisionSound;
         cfx.scrapeSound    = _scrapeSound;
         cfx.sparkSound     = _sparkSound;
     }
 }
        // Not called on parts where physicalSignificance = false. Check the parent part instead.
        public void OnCollisionEnter(Collision c)
        {
            if (_paused)
            {
                return;
            }
            if (c.relativeVelocity.magnitude > 3)
            {
                if (c.contacts.Length == 0)
                {
                    return;
                }

                foreach (ContactPoint contactPoint in c.contacts)
                {
                    Part collidingPart = GetCollidingPart(contactPoint);
                    if (collidingPart != null)
                    {
                        CollisionFX cfx = collidingPart.GetComponent <CollisionFX>();
                        if (cfx != null)
                        {
                            DustImpact(c.relativeVelocity.magnitude, contactPoint.point, c.collider.name);

                            bool isUsableWheel = true;
                            if (cfx.moduleWheel != null)
                            {
                                if (cfx.moduleWheelDamage != null && cfx.moduleWheelDamage.isDamaged)
                                {
                                    isUsableWheel = false;
                                }
                                if (cfx.moduleWheelDeployment != null && cfx.moduleWheelDeployment.Position == 0)
                                {
                                    isUsableWheel = false;
                                }
                            }
                            else
                            {
                                isUsableWheel = false;
                            }

                            cfx.ImpactSounds(isUsableWheel);
                        }
                    }
                }
            }
        }
예제 #4
0
        private void OnCollisionExit(Collision c)
        {
#if DEBUG
            if (useSpheres)
            {
                spheres[3].GetComponent <Renderer>().enabled = false;
            }
#endif

            StopScrapeLightSound();
            foreach (ContactPoint contactPoint in c.contacts)
            {
                Part collidingPart = GetCollidingPart(contactPoint);
                if (collidingPart != null)
                {
                    CollisionFX cfx = collidingPart.GetComponent <CollisionFX>();
                    if (cfx != null)
                    {
                        cfx.StopScrapeLightSound();
                    }
                }
            }
        }
 public CollisionInfo(CollisionFX collisionFX, bool isWheel)
 {
     CollisionFX = collisionFX;
     IsWheel     = isWheel;
 }
        /// <summary>
        /// Whether the object collided with produces sparks.
        /// </summary>
        /// <returns>True if the object is a CollisionFX with scrapeSparks or a non-CollisionFX object.</returns>
        public bool TargetScrapeSparks(GameObject collidedWith)
        {
            CollisionFX objectCollidedWith = collidedWith.GetComponent <CollisionFX>();

            return(objectCollidedWith == null ? true : objectCollidedWith.scrapeSparks);
        }