protected override void AddCollider() { Vector3 upward = (m_TargetDoll.Head.position - m_TargetDoll.Spine.position).normalized; int upDownDirIndex = Utils.GetDirectionIndex(Target, upward); Vector3[] directionsByIndex = new Vector3[] { Target.right, Target.up, Target.forward }; float radius = (0.5f * Vector3.Dot(m_Mesh.bounds.max - Target.position, directionsByIndex[upDownDirIndex])) / Target.lossyScale[upDownDirIndex]; SphereCollider col = MyGameObject.AddComponent <SphereCollider>(); Vector3 centre = Vector3.zero; if (Vector3.Dot(upward, directionsByIndex[upDownDirIndex]) > 0.0f) { centre[upDownDirIndex] = radius; } else { centre[upDownDirIndex] = -radius; } col.center = centre; col.radius = radius; }
// ############################ protected override void AddCollider() { BoxCollider col = MyGameObject.AddComponent <BoxCollider>(); BoxColliderParams p = Utils.CalculateBoxColliderParams(GetLowerBoundPos(), GetUpperBoundPos(), Target, TargetDoll); col.center = p.Centre; col.size = p.Size; }
// ########################### protected override void AddCollider() { Transform child = MyTransform.GetChild(0); if (child != null) { CapsuleCollider col = MyGameObject.AddComponent <CapsuleCollider>(); Vector3 toChild = child.position - MyTransform.position; int dirIndex = Utils.GetDirectionIndex(MyTransform, toChild.normalized); float distanceToChild = toChild.magnitude / MyTransform.lossyScale[dirIndex]; col.center = CalculateCentre(dirIndex, distanceToChild); col.direction = dirIndex; col.radius = distanceToChild * 0.2f; col.height = distanceToChild; } }