pyunity.physics.core module

Core classes of the PyUnity physics engine.

pyunity.physics.core.Infinity = inf

A representation of infinity

class pyunity.physics.core.PhysicMaterial(restitution=0.75, friction=1, immutable=False)[source]

Bases: object

Class to store data on a collider’s material. :param restitution: Bounciness of the material :type restitution: float :param friction: Friction of the material :type friction: float

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
exception(*args, **kwargs)[source]
class pyunity.physics.core.Manifold(a, b, normal, penetration)[source]

Bases: object

Class to store collision data. :param a: The first collider :type a: Collider :param b: The second collider :type b: Collider :param normal: The collision normal :type normal: Vector3 :param penetration: How much the two colliders overlap :type penetration: float

class pyunity.physics.core.Collider(transform)[source]

Bases: pyunity.core.Component

Collider base class.

pos
collidingWith(other)[source]
class pyunity.physics.core.SphereCollider(transform)[source]

Bases: pyunity.physics.core.Collider

A spherical collider that cannot be deformed.

radius

The radius of the SphereCollider

Type:Vector3
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: 1. The sphere’s center is checked to see if it

is inside the AABB.
  1. If it is, then the two are colliding.
  2. If it isn’t, then a copy of the position is clamped to the AABB’s bounds.
  3. Finally, the distance between the clamped position and the original position is measured.
  4. If the distance is bigger than the sphere’s radius, then the two are colliding.
  5. If not, then they aren’t colliding.
class pyunity.physics.core.AABBoxCollider(transform)[source]

Bases: pyunity.physics.core.Collider

An axis-aligned box collider that cannot be deformed.

size

The size of the AABBoxCollider.

Type:Vector3
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: 1. The sphere’s center is checked to see if it

is inside the AABB.
  1. If it is, then the two are colliding.
  2. If it isn’t, then a copy of the position is clamped to the AABB’s bounds.
  3. Finally, the distance between the clamped position and the original position is measured.
  4. If the distance is bigger than the sphere’s radius, then the two are colliding.
  5. If not, then they aren’t colliding.
class pyunity.physics.core.Rigidbody(transform, dummy=False)[source]

Bases: pyunity.core.Component

Class 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
Move(dt)[source]

Moves all colliders on the GameObject by the Rigidbody’s velocity times the delta time. :param dt: Time to simulate movement by :type dt: float

AddForce(force)[source]

Apply a force to the center of the Rigidbody. :param force: Force to apply :type force: Vector3

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. :param impulse: Impulse to apply :type impulse: Vector3

Notes

A force is a gradual change in velocity, whereas an impulse is just a jump in velocity.

class pyunity.physics.core.CollManager[source]

Bases: object

Manages the collisions between all colliders. .. attribute:: 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. :param scene: Scene to search for physics info :type scene: Scene

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.

GetRestitution(a, b)[source]

Get the restitution needed for two rigidbodies, based on their combine function :param a: Rigidbody 1 :type a: Rigidbody :param b: Rigidbody 2 :type b: Rigidbody

Returns:Restitution
Return type:float
CheckCollisions()[source]

Goes through every pair exactly once, then checks their collisions and resolves them.

ResolveCollision(m, rbA, rbB)[source]
correct_inf(a, b, correction, target)[source]
Step(dt)[source]

Steps through the simulation at a given delta time. :param dt: Delta time to step :type dt: float

Notes

The simulation is stepped 10 times manually by the scene, so it is more precise.