Click or drag to resize

CollidersSetSimpleCollider Method

Drops the colliders in all the children objects, and adds one big collider to the parent.

Namespace:  KSPDev.ModelUtils
Assembly:  KSPDev_Utils.2.5 (in KSPDev_Utils.2.5.dll) Version: 2.5 for KSP v1
Syntax
C#
public static Collider SetSimpleCollider(
	GameObject parent,
	PrimitiveType type,
	bool inscribeBoundaryIntoCollider = true
)
Request Example View Source

Parameters

parent
Type: UnityEngineGameObject
Parent object.
type
Type: UnityEnginePrimitiveType
Type of the primitive which describes the parent object most precise in terms of the shape. Only Cube, Sphere, Cylinder, and Capsule are supported. The two latter types produce in the same collider type - the capsule.
inscribeBoundaryIntoCollider (Optional)
Type: SystemBoolean
When calculating the total volume of the object, all its meshes produce a single box boundary. Then, the collider either wraps this box entirely, or sits inside it entirely. If this parameter is true then the collider will cover the boundary box.

Return Value

Type: Collider
The collider created or null.
Remarks
The main purpose of this method is to create one fast collider at the cost of precision. All the meshes in the object (the parent and the children) are processed to produce a single boundary box. Then, this box is applied to the requested primitive type that defines the shape of the final collider.

Note, that radius of the sphere and the capsule colliders is the same on both X and Y axis. If the combined boundary box has any of the dimensions significantly different then it makes sense to choose a different collider type. Or break down the hierarchy into more colliders.

See Also