Ejemplo n.º 1
0
        // 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));
                    }
                }
            }
        }
Ejemplo n.º 2
0
 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;
     }
 }
Ejemplo n.º 3
0
        // 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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Searches child parts for the nearest instance of this class to the given point.
        /// </summary>
        /// <remarks>Parts with physicalSignificance=false have their collisions detected by the parent part.
        /// To identify which part is the source of a collision, check which part the collision is closest to.</remarks>
        /// <param name="parent">The parent part whose children should be tested.</param>
        /// <param name="p">The point to test the distance from.</param>
        /// <returns>The nearest child part's CollisionFX module, or null if the parent part is nearest.</returns>
        private static CollisionInfo GetClosestChild(Part parent, Vector3 p)
        {
            float       parentDistance = Vector3.Distance(parent.transform.position, p);
            float       minDistance    = parentDistance;
            CollisionFX closestChild   = null;
            bool        isWheel        = false;

            foreach (Part child in parent.children)
            {
                if (child != null && child.collider != null &&
                    (child.physicalSignificance == Part.PhysicalSignificance.NONE))
                {
                    float childDistance = Vector3.Distance(child.transform.position, p);
                    var   cfx           = child.GetComponent <CollisionFX>();
                    if (cfx != null)
                    {
                        if (cfx.wheelCollider != null)
                        {
                            float wheelDistance = Vector3.Distance(cfx.wheelCollider.ClosestPointOnBounds(p), p);
                            if (wheelDistance < childDistance)
                            {
                                isWheel       = true;
                                childDistance = wheelDistance;
                            }
                        }

                        if (childDistance < minDistance)
                        {
                            minDistance  = childDistance;
                            closestChild = cfx;
                        }
                        else
                        {
                            isWheel = false;
                        }
                    }
                    else
                    {
                        isWheel = false;
                    }
                }
            }
            return(new CollisionInfo(closestChild, isWheel));
        }
Ejemplo n.º 5
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();
                }
            }
        }
Ejemplo n.º 6
0
 public CollisionInfo(CollisionFX collisionFX, bool isWheel)
 {
     CollisionFX = collisionFX;
     IsWheel     = isWheel;
 }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
0
 public CollisionInfo(CollisionFX collisionFX, bool isWheel)
 {
     CollisionFX = collisionFX;
     IsWheel = isWheel;
 }