10 [RequireComponent(typeof(TSTransform))]
13 public abstract class TSCollider : MonoBehaviour, ICollider {
26 protected set { shape = value; }
29 [FormerlySerializedAs(
"isTrigger")]
31 private bool _isTrigger;
39 return _body.IsColliderOnly;
48 _body.IsColliderOnly = _isTrigger;
59 private TSVector center;
61 private Vector3 scaledCenter;
63 internal RigidBody _body;
107 return this._body.BoundingBox;
138 tsTransform = this.GetComponent<TSTransform>();
139 tsRigidBody = this.GetComponent<TSRigidBody>();
141 if (lossyScale == TSVector.one) {
142 lossyScale = TSVector.Abs(transform.localScale.ToTSVector());
146 public void Update() {
147 if (!Application.isPlaying) {
148 lossyScale = TSVector.Abs(transform.lossyScale.ToTSVector());
152 private void CreateBody() {
153 RigidBody newBody =
new RigidBody(
Shape);
155 if (tsMaterial == null) {
156 tsMaterial = GetComponent<TSMaterial>();
159 if (tsMaterial != null) {
160 newBody.TSFriction = tsMaterial.
friction;
161 newBody.TSRestitution = tsMaterial.
friction;
165 newBody.IsKinematic = tsRigidBody != null && tsRigidBody.
isKinematic;
167 bool isStatic = tsRigidBody == null || tsRigidBody.
isKinematic;
169 if (tsRigidBody != null) {
170 newBody.AffectedByGravity = tsRigidBody.
useGravity;
172 if (tsRigidBody.
mass <= 0) {
173 tsRigidBody.
mass = 1;
176 newBody.Mass = tsRigidBody.
mass;
177 newBody.TSLinearDrag = tsRigidBody.
drag;
180 newBody.SetMassProperties();
184 newBody.AffectedByGravity =
false;
185 newBody.IsStatic =
true;
198 private void CheckPhysics() {
212 Vector3 position = _body != null ? _body.Position.ToVector() : (transform.position +
ScaledCenter.ToVector());
213 Quaternion rotation = _body != null ? _body.Orientation.ToQuaternion() : transform.rotation;
215 Gizmos.color = Color.yellow;
217 Matrix4x4 cubeTransform = Matrix4x4.TRS(position, rotation,
GetGizmosSize());
218 Matrix4x4 oldGizmosMatrix = Gizmos.matrix;
220 Gizmos.matrix *= cubeTransform;
224 Gizmos.matrix = oldGizmosMatrix;
242 return _body != null;
Shape Shape
Shape used by a collider.
bool useGravity
If true it uses gravity force.
FP drag
Linear drag coeficient.
Represents a physical 3D rigid body.
bool isTrigger
If it is only a trigger and doesn't interfere on collisions.
static IPhysicsManager instance
Returns a proper implementation of IPhysicsManager.
bool isKinematic
If true it doesn't get influences from external forces.
Simulates physical properties of a body.
FP friction
Static friction when in contact.
Abstract collider for 3D shapes.
TSVector ScaledCenter
Returns a version of collider's center scaled by parent's transform.
TSBBox bounds
Returns body's boundind box.
TSRigidBody attachedRigidbody
Returns the TSRigidBody attached.
TSVector lossyScale
Holds an first value of the GameObject's lossy scale.
void Awake()
Creates a new TSRigidBody when there is no one attached to this GameObject.
FP angularDrag
Angular drag coeficient.
abstract Shape CreateShape()
Creates the shape related to a concrete implementation of TSCollider.
void Initialize()
Initializes Shape and RigidBody and sets initial values to position and orientation based on Unity's ...
abstract void DrawGizmos()
Draws the specific gizmos of concrete collider (for example "Gizmos.DrawWireCube" for a TSBoxCollider...
TSVector Center
Center of the collider shape.
Manages physics simulation.
abstract Vector3 GetGizmosSize()
Returns the gizmos size.
bool IsBodyInitialized
Returns true if the body was already initialized.
IBody3D Body
Returns the body linked to this collider.
virtual void OnDrawGizmos()
Do a base matrix transformation to draw correctly all collider gizmos.
TSMaterial tsMaterial
Simulated material.