//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// namespace BansheeEngine { /** @addtogroup Physics * @{ */ /// /// Collider with capsule geometry. /// public sealed class CapsuleCollider : Collider { [SerializeField] private float radius = 0.2f; [SerializeField] private float halfHeight = 1.0f; [SerializeField] private Vector3 normal = Vector3.YAxis; /// /// Radius of the capsule. /// public float Radius { get { return radius; } set { value = MathEx.Max(value, 0.01f); if (radius == value) return; radius = value; if (Native != null) { Native.Radius = value; if (parent != null) parent.UpdateMassDistribution(); } } } /// /// Half height of the capsule, from the origin to one of the hemispherical centers, along the normal vector. /// public float HalfHeight { get { return halfHeight; } set { value = MathEx.Max(value, 0.01f); if (halfHeight == value) return; halfHeight = value; if (Native != null) { Native.HalfHeight = value; if (parent != null) parent.UpdateMassDistribution(); } } } /// /// Position of the capsule shape, relative to the component's scene object. /// public Vector3 Center { get { return serializableData.localPosition; } set { if (serializableData.localPosition == value) return; serializableData.localPosition = value; if (Native != null) UpdateTransform(); } } /// /// Normal vector of the capsule. It determines how is the capsule oriented. /// public Vector3 Normal { get { return normal; } set { if (normal == value) return; normal = value.Normalized; serializableData.localRotation = Quaternion.FromToRotation(Vector3.XAxis, normal); if (Native != null) UpdateTransform(); } } public CapsuleCollider() { serializableData.localRotation = Quaternion.FromToRotation(Vector3.XAxis, normal); } /// /// Returns the native capsule collider wrapped by this component. /// private NativeCapsuleCollider Native { get { return (NativeCapsuleCollider)native; } } /// internal override NativeCollider CreateCollider() { NativeCapsuleCollider capsuleCollider = new NativeCapsuleCollider(); capsuleCollider.Radius = radius; capsuleCollider.HalfHeight = halfHeight; return capsuleCollider; } } /** @} */ }