PhysicsBody

p5ex~ PhysicsBody

(To be filled)

Constructor

new PhysicsBody()

Source:

Members

vx

X velocity.
Source:

vy

Y velocity.
Source:

vz

Z velocity.
Source:

x

X position.
Source:

y

Y position.
Source:

z

Z position.
Source:

Methods

accelerate(x, y, z)

Accelerates the body.
Source:
Parameters:
Name Type Description
x
y
z

addSpeed(speedChange)

Add the provided value to the speed of the body.
Source:
Parameters:
Name Type Description
speedChange

applyForce(force)

Apply the provided force to the body.
Source:
Parameters:
Name Type Description
force

attractEachOther(other, magnitudeFactor, minMag, maxMag, cutoffMag)

Applies attraction force to both this and the target body.
Source:
Parameters:
Name Type Default Description
other PhysicsBody the other body to interact with
magnitudeFactor number the factor of magnitude other than the distance
minMag number 0 the minimum magnitude
maxMag number the maximum magnitude
cutoffMag number does not apply force if magnitude is smaller than this

attractToPoint(targetPosition, magnitudeFactor, minMag, maxMag, cutoffMag)

Applies attraction force to this body.
Source:
Parameters:
Name Type Default Description
targetPosition p5.Vector the target position
magnitudeFactor number the factor of magnitude other than the distance
minMag number 0 the minimum magnitude
maxMag number the maximum magnitude
cutoffMag number does not apply force if magnitude is smaller than this

bounce(normalUnitVector, restitution)

(To be filled)
Source:
Parameters:
Name Type Default Description
normalUnitVector
restitution 1

collides(other)

Returns true if the body collides the provided body.
Source:
Parameters:
Name Type Description
other

constrainSpeed(maxSpeed)

Constrains the current speed. Should be called every time if needed.
Source:
Parameters:
Name Type Description
maxSpeed

getDirection()

Returns the current direction angle.
Source:

getSpeed()

Returns the current speed.
Source:

setFriction(constant)

Sets the friction of the body.
Source:
Parameters:
Name Type Description
constant

step()

Updates the body.
Source: