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
Source code: pyunity/physics/core.py
Core classes of the PyUnity
physics engine.
-
pyunity.physics.core.Infinity = inf
Type: float
A representation of infinity
-
class pyunity.physics.core.PhysicMaterial[source]
Bases: object
Class to store data on a collider’s material.
- Parameters:
-
-
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[source]
Bases: object
Class to store collision data.
- Parameters:
a (Collider) – The first collider
b (Collider) – The second collider
point (Vector3) – The collision point
normal (Vector3) – The collision normal
penetration (float) – How much the two colliders overlap
-
class pyunity.physics.core.Collider[source]
Bases: Component
Collider base class.
-
offset = None
The offset from the centre of the Collider
- Type:
Vector3
-
supportPoint(direction)[source]
-
property pos
-
property rot
-
class pyunity.physics.core.SphereCollider[source]
Bases: Collider
A spherical collider that cannot be
deformed.
-
radius = 0.0
The radius of the SphereCollider
- Type:
Vector3
-
SetSize(radius, offset)[source]
Sets the size of the collider.
- Parameters:
-
-
property min
-
property max
-
collidingWith(other)[source]
-
supportPoint(direction)[source]
-
class pyunity.physics.core.BoxCollider[source]
Bases: Collider
An axis-aligned box collider that
cannot be deformed.
-
size = None
The distance between two farthest
vertices of the collider
- Type:
Vector3
-
SetSize(size, offset)[source]
Sets the size of the collider.
- Parameters:
-
-
property min
-
property max
-
collidingWith(other)[source]
-
supportPoint(direction)[source]
-
class pyunity.physics.core.Rigidbody[source]
Bases: Component
Class to let a GameObject follow physics
rules.
-
velocity = None
Velocity of the Rigidbody
- Type:
Vector3
-
rotVel = None
Rotational velocity of the Rigidbody
- Type:
Vector3
-
force = None
Force acting on the Rigidbody. Reset every
frame.
- Type:
Vector3
-
torque = None
Rotational force acting on the Rigidbody.
Reset every frame.
- Type:
Vector3
-
physicMaterial = <pyunity.physics.core.PhysicMaterial object at 0x7fc4aa61a5b0>
Physics material of the Rigidbody
- Type:
PhysicMaterial
-
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 (float) – Time to simulate movement by
-
MovePos(offset)[source]
Moves the rigidbody and its colliders
by an offset.
- Parameters:
offset (Vector3) – Offset to move
-
AddForce(force, point=Vector3(0, 0, 0))[source]
Apply a force to the center of the Rigidbody.
- Parameters:
force (Vector3) – Force to apply
point (Vector3, 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.
-
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.
-
class pyunity.physics.core.SupportPoint[source]
Bases: IgnoredMixin
-
class pyunity.physics.core.Triangle[source]
Bases: IgnoredMixin
-
class pyunity.physics.core.CollManager[source]
Bases: IgnoredMixin
Manages 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
-
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 AddEdge(edges, a, b)[source]
-
static barycentric(p, a, b, c)[source]
-
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.
-
GetRestitution(a, b)[source]
Get the restitution needed for
two rigidbodies, based on their
combine function
- Parameters:
-
- Returns:
Restitution
- Return type:
float
-
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 (float) – Delta time to step
Notes
The simulation is stepped 10 times
manually by the scene, so it is more
precise.