/// <summary> Adds all of the colliderObjects to a handy dictionary named collToPart. /// Also determines the length of this body part by looking at all of these colliders, /// thenceby setting _topVector </summary> /// <param name="characterPhysics">The parent CharacterPhysics class</param> internal void Initialize(CharacterPhysics characterPhysics) { _pp = characterPhysics; if (parentPart != null) { _parent = _pp.bodyParts.First(part => part.bodyPart == parentPart); } _rb = _pp.gameObject.GetComponent <Rigidbody2D>(); _root = _pp.transform; Vector3 objPos = bodyPart.transform.position; Vector3 farPoint = objPos; Collider2D farColl = bodyPart.GetComponent <Collider2D>(); foreach (GameObject co in colliderObjects) { Collider2D[] colliders = co.GetComponents <Collider2D>(); foreach (Collider2D collider in colliders) { if (Vector3.Distance(collider.bounds.center, objPos) >= Vector3.Distance(farPoint, objPos)) { farPoint = collider.bounds.center; farColl = collider; } _pp.collToPart.Add(collider, this); } } farPoint = Vector3.Distance(farPoint + farColl.bounds.extents, objPos) < Vector3.Distance(farPoint - farColl.bounds.extents, objPos) ? bodyPart.transform.InverseTransformPoint(farPoint - farColl.bounds.extents) : bodyPart.transform.InverseTransformPoint(farPoint + farColl.bounds.extents); _topVector = new Vector3(farPoint.x, 0); if (lowerLimit < -360) { float old = lowerLimit; lowerLimit %= 360; upperLimit += lowerLimit - old; } if (upperLimit > 720) { float old = upperLimit; upperLimit %= 360; lowerLimit += upperLimit - old; } if (isLeg) { // _pp.StartCoroutine(_CheckStep()); //TODO FIXME Checkstep is dumb and bad and needs to be made less bad List <GameObject> partsTemp = _pp._nonLegBendParts.ToList(); List <float> amountsTemp = _pp._nonLegBendAmounts.ToList(); partsTemp.AddRange(bendParts); amountsTemp.AddRange(bendAmounts); _pp._nonLegBendParts = partsTemp.ToArray(); _pp._nonLegBendAmounts = amountsTemp.ToArray(); } }
/// <summary> Partially/completely suppress the physics system for a list of parts </summary> /// <param name="mods"> List of mods, which specify the part, extent, and duration of suppression </param> public void SuppressPhysics(List <CharacterPhysicsMod> mods) { foreach (var mod in mods) { BodyPartClass part = collToPart[mod.collider]; part.SuppressAmount = mod.dampPercent; } if (_actuallySuppressPhysics == null) { _actuallySuppressPhysics = StartCoroutine(_ActuallySuppressPhysics()); } }