Physics 2D - Wantcha/Chimera GitHub Wiki
Physics 2D variables and functions
Rigid Body 2D Component
RigidBody2D Component is a variable type controlling the parameters of a RigidBody2D. It can be retrieved from an entity using the GetRigidBody2DComponent() function.
- float RigidBody2DComponent.gravityScale
The value of the gravity multiplier applied to this body.
- bool RigidBody2DComponent.discreteCollision
Whether the colliders linked to this body should use discrete collision.
- bool RigidBody2DComponent.fixedRotation
Whether this body should have a constant rotation.
- Body2DType RigidBody2DComponent.bodyType
The type of body properties this body should have (see below).
- Vector2 RigidBody2DComponent.velocity
The linear velocity of this body.
- void RigidBody2DComponent:ApplyForce(Vector2 force)
Apply the specified force to this body.
- void RigidBody2DComponent:ApplyForceAtPoint(Vector2 force, Vector2 position)
Apply the specified force to this body at the specified position.
Body 2D Type
Body2DType is an enumerator listing the 3 types of 2D body used in the RigidBody2D Component. These are:
- Body2DType.Static
- Body2DType.Kinematic
- Body2DType.Dynamic
Box Collider 2D Component
BoxCollider2D Component is a variable type controlling the parameters of a BoxCollider2D. It can be retrieved from an entity using the GetBoxCollider2DComponent() function.
- bool BoxCollider2DComponent.isSensor
Property indicating whether this collider is a sensor.
- float BoxCollider2DComponent.friction
The friction coefficient of this collider.
- float BoxCollider2DComponent.friction
The friction coefficient of this collider.
- float BoxCollider2DComponent.density
The density value of this collider.
- float BoxCollider2DComponent.bounciness
The bounciness value of this collider.
- void BoxCollider2DComponent:SetSize(Vector2 size)
- void BoxCollider2DComponent:SetSize(float x, float y)
Sets the 2D size of this box collider.
- Vector2 BoxCollider2DComponent:GetSize()
Returns the 2D size of this box collider.
- void BoxCollider2DComponent:SetCenter(Vector2 position)
- void BoxCollider2DComponent:SetCenter(float x, float y)
Sets the center of this collider (relative to the entity's position).
- Vector2 BoxCollider2DComponent:GetCenter()
Returns the 2D position of this box collider (relative to the entity's position).
Circle Collider 2D Component
CircleCollider2D Component is a variable type controlling the parameters of a CircleCollider2D. It can be retrieved from an entity using the GetCircleCollider2DComponent() function.
In terms of functions, the CircleCollider2D Component has almost identical properties to the BoxCollider2D Component. The only difference is that the SetSize() and GetSize() functions are replaced with:
- float CircleCollider2DComponent.radius
Value controlling the radius of this circle collider.
Contact2D
Variable type usually returned by the built-in CollisionEnter2D and CollisionExit2D callback functions that contains information about a collision.
- Entity Contact2D.entity
The entity with which the current entity collided with.
- Collider2D Contact2D.collider
The collider of this entity that detected the collision update.
- Collider2D Contact2D.otherCollider
The collider of the collided entity that detected the collision update.
- int Contact2D.contactCount
The number of collision points detected (can be either 1 or 2)
- Vector2[] Contact2D.contactPositions
The 2D positions of the detected collisions.
- Vector2 Contact2D.normal
The 2D direction vector of the collision normal.
Collider2D
Variable type from which the 2D collider components inherit from.
- bool Collider2D.isSensor
Property indicating whether this collider is a sensor.
- float Collider2D.friction
The friction coefficient of this collider.
- float Collider2D.friction
The friction coefficient of this collider.
- float Collider2D.density
The density value of this collider.
- Entity Collider2D.GetEntity()
The entity on which this collider sits on.