pyunity.physics.core module¶
Core classes of the PyUnity physics engine.
-
class
pyunity.physics.core.AABBoxCollider[source]¶ Bases:
pyunity.physics.core.ColliderAn axis-aligned box collider that cannot be deformed.
-
min¶ The corner with the lowest coordinates.
Type: Vector3
-
max¶ The corner with the highest coordinates.
Type: Vector3
-
pos¶ The center of the AABBoxCollider
Type: Vector3
-
AddComponent(component)¶ Calls AddComponent on the component’s GameObject.
Parameters: component (Component) – Component to add. Must inherit from Component
-
CheckOverlap(other)[source]¶ Checks to see if the bounding box of two colliders overlap.
Parameters: other (Collider) – Other collider to check against Returns: Whether they are overlapping or not Return type: bool
-
GetComponent(component)¶ Calls GetComponent on the component’s GameObject.
Parameters: componentClass (Component) – Component to get. Must inherit from Component
-
SetSize(min, max)[source]¶ Sets the size of the collider.
Parameters: - min (Vector3) – The corner with the lowest coordinates.
- max (Vector3) – The corner with the highest coordinates.
-
collidingWith(other)[source]¶ Check to see if the collider is colliding with another collider.
Parameters: other (Collider) – Other collider to check against Returns: Collision data Return type: Manifold or None Notes
To check against another AABBoxCollider, the corners are checked to see if they are inside the other collider.
To check against a SphereCollider, the check is as follows:
- The sphere’s center is checked to see if it is inside the AABB.
- If it is, then the two are colliding.
- If it isn’t, then a copy of the position is clamped to the AABB’s bounds.
- Finally, the distance between the clamped position and the original position is measured.
- If the distance is bigger than the sphere’s radius, then the two are colliding.
- If not, then they aren’t colliding.
-
-
class
pyunity.physics.core.CollManager[source]¶ Bases:
objectManages the collisions between all colliders.
-
rigidbodies¶ Dictionary of rigidbodies andthe colliders on the gameObject that the Rigidbody belongs to
Type: dict
-
dummyRigidbody¶ A dummy rigidbody used when a GameObject has colliders but no rigidbody. It has infinite mass
Type: Rigidbody
-
AddPhysicsInfo(scene)[source]¶ Get all colliders and rigidbodies from a specified scene. This overwrites the collider and rigidbody lists, and so can be called whenever a new collider or rigidbody is added or removed.
Parameters: scene (Scene) – Scene to search for physics info Notes
This function will overwrite the pre-existing dictionary of rigidbodies. When there are colliders but no rigidbody is on the GameObject, then they are placed in the dictionary with a dummy Rigidbody that has infinite mass and a default physic material. Thus, they cannot move.
-
CheckCollisions()[source]¶ Goes through every pair exactly once, then checks their collisions and resolves them.
-
-
class
pyunity.physics.core.Collider[source]¶ Bases:
pyunity.core.ComponentCollider base class.
-
class
pyunity.physics.core.Manifold(a, b, normal, penetration)[source]¶ Bases:
objectClass to store collision data.
Parameters:
-
class
pyunity.physics.core.PhysicMaterial(restitution=0.75, friction=1)[source]¶ Bases:
objectClass to store data on a collider’s material.
Parameters: - restitution (float) – Bounciness of the material
- friction (float) – Friction of the material
-
restitution¶ Bounciness of the material
Type: float
-
friction¶ Friction of the material
Type: float
-
combine¶ Combining function. -1 means minimum, 0 means average, and 1 means maximum
Type: int
-
class
pyunity.physics.core.Rigidbody[source]¶ Bases:
pyunity.core.ComponentClass to let a GameObject follow physics rules.
-
mass¶ Mass of the Rigidbody. Defaults to 100
Type: int or float
-
velocity¶ Velocity of the Rigidbody
Type: Vector3
-
physicMaterial¶ Physics material of the Rigidbody
Type: PhysicMaterial
-
position¶ Position of the Rigidbody. It is assigned to its GameObject’s position when the CollHandler is created
Type: Vector3
-
AddComponent(component)¶ Calls AddComponent on the component’s GameObject.
Parameters: component (Component) – Component to add. Must inherit from Component
-
AddForce(force)[source]¶ Apply a force to the center of the Rigidbody.
Parameters: force (Vector3) – Force to apply Notes
A force is a gradual change in velocity, whereas an impulse is just a jump in velocity.
-
AddImpulse(impulse)[source]¶ Apply an impulse to the center of the Rigidbody.
Parameters: impulse (Vector3) – Impulse to apply Notes
A force is a gradual change in velocity, whereas an impulse is just a jump in velocity.
-
GetComponent(component)¶ Calls GetComponent on the component’s GameObject.
Parameters: componentClass (Component) – Component to get. Must inherit from Component
-
-
class
pyunity.physics.core.SphereCollider[source]¶ Bases:
pyunity.physics.core.ColliderA spherical collider that cannot be deformed.
-
min¶ The corner with the lowest coordinates.
Type: Vector3
-
max¶ The corner with the highest coordinates.
Type: Vector3
-
pos¶ The center of the SphereCollider
Type: Vector3
-
radius¶ The radius of the SphereCollider
Type: Vector3
-
AddComponent(component)¶ Calls AddComponent on the component’s GameObject.
Parameters: component (Component) – Component to add. Must inherit from Component
-
CheckOverlap(other)[source]¶ Checks to see if the bounding box of two colliders overlap.
Parameters: other (Collider) – Other collider to check against Returns: Whether they are overlapping or not Return type: bool
-
GetComponent(component)¶ Calls GetComponent on the component’s GameObject.
Parameters: componentClass (Component) – Component to get. Must inherit from Component
-
SetSize(radius, offset)[source]¶ Sets the size of the collider.
Parameters: - radius (float) – The radius of the collider.
- offset (Vector3) – Offset of the collider.
-
collidingWith(other)[source]¶ Check to see if the collider is colliding with another collider.
Parameters: other (Collider) – Other collider to check against Returns: Collision data Return type: Manifold or None Notes
To check against another SphereCollider, the distance and the sum of the radii is checked.
To check against an AABBoxColider, the check is as follows:
- The sphere’s center is checked to see if it is inside the AABB.
- If it is, then the two are colliding.
- If it isn’t, then a copy of the position is clamped to the AABB’s bounds.
- Finally, the distance between the clamped position and the original position is measured.
- If the distance is bigger than the sphere’s radius, then the two are colliding.
- If not, then they aren’t colliding.
-
-
pyunity.physics.core.infinity= inf¶ A representation of infinity