Attention

You are viewing PyUnity docs under the develop branch. As such, they are only applicable if you installed from source. Go to https://docs.pyunity.x10.bz/en/latest/ for the most recent release.

# pyunity.physics.core module¶

Core classes of the PyUnity physics engine.

pyunity.physics.core.Infinity = inf

Type:

A representation of infinity

class pyunity.physics.core.PhysicMaterial[source]

Bases:

Class to store data on a collider’s material.

Parameters
• restitution () – Bounciness of the material

• friction () – Friction of the material

restitution

Bounciness of the material

Type

friction

Friction of the material

Type

combine

Combining function. -1 means minimum, 0 means average, and 1 means maximum

Type

exception(*args, **kwargs)[source]
class pyunity.physics.core.Manifold[source]

Bases:

Class to store collision data.

Parameters
• a () – The first collider

• b () – The second collider

• point () – The collision point

• normal () – The collision normal

• penetration () – How much the two colliders overlap

class pyunity.physics.core.Collider[source]

Bases:

Collider base class.

supportPoint(direction)[source]
property pos
property rot
class pyunity.physics.core.SphereCollider[source]

Bases:

A spherical collider that cannot be deformed.

offset = None

The offset from the centre of the SphereCollider

Type

Type

Sets the size of the collider.

Parameters

• offset () – Offset of the collider.

property min
property max
collidingWith(other)[source]
supportPoint(direction)[source]
class pyunity.physics.core.BoxCollider[source]

Bases:

An axis-aligned box collider that cannot be deformed.

size = None

The distance between two farthest vertices of the collider

Type

offset = None

The offset from the centre of the collider

Type

property min
property max
collidingWith(other)[source]
supportPoint(direction)[source]
class pyunity.physics.core.Rigidbody[source]

Bases:

Class to let a GameObject follow physics rules.

velocity = None

Velocity of the Rigidbody

Type

rotVel = None

Rotational velocity of the Rigidbody

Type

force = None

Force acting on the Rigidbody. Reset every frame.

Type

torque = None

Rotational force acting on the Rigidbody. Reset every frame.

Type

physicMaterial = <pyunity.physics.core.PhysicMaterial object at 0x7fa605495a90>

Physics material of the Rigidbody

Type

property mass

Mass of the Rigidbody. Defaults to 100

property inertia
property pos
property rot
Move(dt)[source]

Moves all colliders on the GameObject by the Rigidbody’s velocity times the delta time.

Parameters

dt () – Time to simulate movement by

MovePos(offset)[source]

Moves the rigidbody and its colliders by an offset.

Parameters

offset () – Offset to move

Apply a force to the center of the Rigidbody.

Parameters
• force () – Force to apply

• point (, optional) – Point relative to center of mass in local space to apply force at

Notes

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

Apply an impulse to the center of the Rigidbody.

Parameters

impulse () – Impulse to apply

Notes

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

class pyunity.physics.core.SupportPoint[source]

Bases:

class pyunity.physics.core.Triangle[source]

Bases:

class pyunity.physics.core.CollManager[source]

Bases:

Manages the collisions between all colliders.

rigidbodies

Dictionary of rigidbodies andthe colliders on the gameObject that the Rigidbody belongs to

Type

dummyRigidbody

A dummy rigidbody used when a GameObject has colliders but no rigidbody. It has infinite mass

Type

static supportPoint(a, b, direction)[source]
static nextSimplex(args)[source]
static lineSimplex(args)[source]
static triSimplex(args)[source]
static tetraSimplex(args)[source]
static gjk(a, b)[source]
static epa(a, b)[source]
static barycentric(p, a, b, c)[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 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.

GetRestitution(a, b)[source]

Get the restitution needed for two rigidbodies, based on their combine function

Parameters
Returns

Restitution

Return type

CheckCollisions()[source]

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

ResolveCollisions(a, b, point, restitution, normal, penetration)[source]
correctInf(a, b, correction, target)[source]
Step(dt)[source]

Steps through the simulation at a given delta time.

Parameters

dt () – Delta time to step

Notes

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