I want a function that will return the array element that represents the maximum value in a Vector3. Here’s what I have right now (meshBounds.size is a Vector3). Can it get better?
// capsuleCollider.direction defaults to 1 (Y-Axis)
if (meshBounds.size.x > meshBounds.size.y)
{
if (meshBounds.size.z > meshBounds.size.x)
capsuleCollider.direction = 2;
else
capsuleCollider.direction = 0;
}
else if (meshBounds.size.z > meshBounds.size.y)
capsuleCollider.direction = 2;
Here’s the full extent of what I need to do. It works, but I’m sure I’m going about it like an idiot. :roll: Advice appreciated.
if (meshBounds.size.x > meshBounds.size.y)
{
// capsule is elongated along its local Z axis
if (meshBounds.size.z > meshBounds.size.x)
{
capsuleCollider.radius = (meshBounds.extents.x + meshBounds.extents.y) * .5F;
capsuleCollider.height = meshBounds.size.z;
capsuleCollider.direction = 2;
}
// capsule is elongated along its local X axis
else
{
capsuleCollider.radius = (meshBounds.extents.y + meshBounds.extents.z) * .5F;
capsuleCollider.height = meshBounds.size.x;
capsuleCollider.direction = 0;
}
}
else if (meshBounds.size.z > meshBounds.size.y)
{
// capsule is elongated along its local Z axis
capsuleCollider.radius = (meshBounds.extents.x + meshBounds.extents.y) * .5F;
capsuleCollider.height = meshBounds.size.z;
capsuleCollider.direction = 2;
}
// capsule is elongated along its local Y axis
else
{
capsuleCollider.radius = (meshBounds.extents.x + meshBounds.extents.z) * .5F;
capsuleCollider.height = meshBounds.size.y;
// capsuleCollider.direction defaults to 1 (Y-Axis)
}
I forced myself always to ‘f’ float constants. With that habit, I can completely avoid running into conversion warnings, without having to think about it ;).