9 [RequireComponent(typeof(TSTransform))]
12 public abstract class TSCollider : MonoBehaviour, ICollider {
25 protected set { shape = value; }
41 private Vector3 scaledCenter;
43 internal RigidBody _body;
87 return this._body.BoundingBox;
118 tsTransform = this.GetComponent<TSTransform>();
119 tsRigidBody = this.GetComponent<TSRigidBody>();
122 lossyScale =
TSVector.Abs(transform.localScale.ToTSVector());
126 public void Update() {
127 if (!Application.isPlaying) {
128 lossyScale =
TSVector.Abs(transform.lossyScale.ToTSVector());
132 private void CreateBody() {
133 RigidBody newBody =
new RigidBody(
Shape);
135 if (tsMaterial == null) {
136 tsMaterial = GetComponent<TSMaterial>();
139 if (tsMaterial != null) {
140 newBody.Material =
new BodyMaterial();
141 newBody.Material.KineticFriction = tsMaterial.
friction;
142 newBody.Material.StaticFriction = tsMaterial.
friction;
143 newBody.Material.Restitution = tsMaterial.
restitution;
147 newBody.IsKinematic = tsRigidBody != null && tsRigidBody.
isKinematic;
149 bool isStatic = tsRigidBody == null || tsRigidBody.
isKinematic;
152 newBody.AffectedByGravity =
false;
153 newBody.IsStatic =
true;
154 }
else if (tsRigidBody != null) {
155 newBody.AffectedByGravity = tsRigidBody.
useGravity;
157 if (tsRigidBody.
mass <= 0) {
158 tsRigidBody.
mass = 1;
161 newBody.Mass = tsRigidBody.
mass;
163 newBody.SetMassProperties();
176 private void CheckPhysics() {
190 Vector3 position = _body != null ? _body.Position.ToVector() : (transform.position +
ScaledCenter.ToVector());
191 Quaternion rotation = _body != null ? _body.Orientation.ToQuaternion() : transform.rotation;
193 Gizmos.color = Color.yellow;
195 Matrix4x4 cubeTransform = Matrix4x4.TRS(position, rotation,
GetGizmosSize());
196 Matrix4x4 oldGizmosMatrix = Gizmos.matrix;
198 Gizmos.matrix *= cubeTransform;
202 Gizmos.matrix = oldGizmosMatrix;
220 return _body != null;
Shape Shape
Shape used by a collider.
bool useGravity
If true it uses gravity force.
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.
void Scale(TSVector other)
Multiplies each component of the vector by the same components of the provided vector.
bool isKinematic
If true it doesn't get influences from external forces.
Simulates physical properties of a body.
static readonly TSVector one
A vector with components (1,1,1);
FP friction
Static friction when in contact.
Abstract collider for 3D shapes.
FP restitution
Coeficient of restitution.
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.
Represents an interface to 3D bodies.
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.
Bounding Box defined through min and max vectors.