// 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); } } } } }
/// <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)); }
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); }
public CollisionInfo(CollisionFX collisionFX, bool isWheel) { CollisionFX = collisionFX; IsWheel = isWheel; }