Table of Contents

Class PhysicsGm

Namespace
Gamem
Assembly
Gamem.dll

Provides static mathematical methods for basic physics calculations like gravity, friction, and movement interpolation.

public static class PhysicsGm
Inheritance
PhysicsGm
Inherited Members

Methods

AddForce(double, double, double, double)

Applies a continuous force over a specified time duration to update the velocity, based on Newton's second law.

public static double AddForce(double v, double F, double t, double m)

Parameters

v double

The initial velocity before the force is applied.

F double

The force magnitude.

t double

The duration of time over which the force acts.

m double

The mass of the object. If mass is 0, the velocity remains unchanged to avoid division by zero.

Returns

double

The updated velocity after applying the force.

AddForce(float, float, float, float)

Applies a continuous force over a specified time duration to update the velocity, based on Newton's second law.

public static float AddForce(float v, float F, float t, float m)

Parameters

v float

The initial velocity before the force is applied.

F float

The force magnitude.

t float

The duration of time over which the force acts.

m float

The mass of the object. If mass is 0, the velocity remains unchanged to avoid division by zero.

Returns

float

The updated velocity after applying the force.

AddImpulse(double, double, double)

Applies an instantaneous impulse to update the velocity.

public static double AddImpulse(double vOld, double J, double m)

Parameters

vOld double

The pre-impulse velocity.

J double

The impulse magnitude (change in momentum).

m double

The mass of the object. If mass is 0, the velocity remains unchanged to avoid division by zero.

Returns

double

The updated velocity after the impulse is applied.

AddImpulse(float, float, float)

Applies an instantaneous impulse to update the velocity.

public static float AddImpulse(float vOld, float J, float m)

Parameters

vOld float

The pre-impulse velocity.

J float

The impulse magnitude (change in momentum).

m float

The mass of the object. If mass is 0, the velocity remains unchanged to avoid division by zero.

Returns

float

The updated velocity after the impulse is applied.

ApplyFriction(double, double, double)

Applies friction to reduce velocity towards zero over a specified time step.

public static double ApplyFriction(double velocity, double frictionCoeff, double deltaTime)

Parameters

velocity double

The current velocity.

frictionCoeff double

The friction coefficient representing deceleration per second.

deltaTime double

The time elapsed since the last frame in seconds.

Returns

double

The updated velocity after friction is applied, clamping to 0.0 if it changes direction.

ApplyFriction(float, float, float)

Applies friction to reduce velocity towards zero over a specified time step.

public static float ApplyFriction(float velocity, float frictionCoeff, float deltaTime)

Parameters

velocity float

The current velocity.

frictionCoeff float

The friction coefficient representing deceleration per second.

deltaTime float

The time elapsed since the last frame in seconds.

Returns

float

The updated velocity after friction is applied, clamping to 0.0 if it changes direction.

ApplyGravity(double, double, double)

Applies gravity to the current vertical velocity over a specified time step.

public static double ApplyGravity(double velocity, double gravity, double deltaTime)

Parameters

velocity double

The current velocity.

gravity double

The acceleration due to gravity.

deltaTime double

The time elapsed since the last frame in seconds.

Returns

double

The updated velocity after applying gravity.

ApplyGravity(float, float, float)

Applies gravity to the current vertical velocity over a specified time step.

public static float ApplyGravity(float velocity, float gravity, float deltaTime)

Parameters

velocity float

The current velocity.

gravity float

The acceleration due to gravity.

deltaTime float

The time elapsed since the last frame in seconds.

Returns

float

The updated velocity after applying gravity.

ApplyQuadraticDrag(double, double, double)

Applies quadratic drag (air resistance) to a velocity value over a given time step using Euler integration.

public static double ApplyQuadraticDrag(double v, double k, double t)

Parameters

v double

The current velocity.

k double

The quadratic drag coefficient (typically dependent on fluid density, drag coefficient, and cross-sectional area).

t double

The time step (delta time) in seconds.

Returns

double

The updated velocity after quadratic drag has been applied.

ApplyQuadraticDrag(float, float, float)

Applies quadratic drag (air resistance) to a velocity value over a given time step using Euler integration.

public static float ApplyQuadraticDrag(float v, float k, float t)

Parameters

v float

The current velocity.

k float

The quadratic drag coefficient (typically dependent on fluid density, drag coefficient, and cross-sectional area).

t float

The time step (delta time) in seconds.

Returns

float

The updated velocity after quadratic drag has been applied.

Bounce(double, double, double)

Calculates the velocity after a bounce collision, reversing direction and applying a coefficient of restitution.

public static double Bounce(double vOld, double bounciness, double minBounceThreshold = 0.1)

Parameters

vOld double

The pre-collision velocity.

bounciness double

The bounciness coefficient (restitution), clamped between 0.0 and 1.0.

minBounceThreshold double

The minimum velocity required to sustain a bounce. Below this magnitude, the velocity is clamped to zero to prevent endless micro-bouncing.

Returns

double

The updated velocity after the bounce, or 0.0 if the resulting speed falls below the threshold.

Bounce(float, float, float)

Calculates the velocity after a bounce collision, reversing direction and applying a coefficient of restitution.

public static float Bounce(float vOld, float bounciness, float minBounceThreshold = 0.1)

Parameters

vOld float

The pre-collision velocity.

bounciness float

The bounciness coefficient (restitution), clamped between 0.0 and 1.0.

minBounceThreshold float

The minimum velocity required to sustain a bounce. Below this magnitude, the velocity is clamped to zero to prevent endless micro-bouncing.

Returns

float

The updated velocity after the bounce, or 0.0 if the resulting speed falls below the threshold.

CalculateCentripetalAcceleration(double, double)

Calculates the centripetal acceleration of an object moving along a circular path.

public static double CalculateCentripetalAcceleration(double speed, double radius)

Parameters

speed double

The linear speed of the object.

radius double

The radius of the circular path.

Returns

double

The centripetal acceleration, or zero if radius is zero.

CalculateCentripetalAcceleration(float, float)

Calculates the centripetal acceleration of an object moving along a circular path.

public static float CalculateCentripetalAcceleration(float speed, float radius)

Parameters

speed float

The linear speed of the object.

radius float

The radius of the circular path.

Returns

float

The centripetal acceleration, or zero if radius is zero.

CalculateJumpVelocity(double, double)

Calculates the initial upward velocity required to reach a specific jump height under a given gravity.

public static double CalculateJumpVelocity(double h, double g)

Parameters

h double

The target maximum jump height.

g double

The gravity value. Its absolute value is used to ensure mathematical stability.

Returns

double

The calculated initial jump velocity required to reach the target height.

CalculateJumpVelocity(float, float)

Calculates the initial upward velocity required to reach a specific jump height under a given gravity.

public static float CalculateJumpVelocity(float h, float g)

Parameters

h float

The target maximum jump height.

g float

The gravity value. Its absolute value is used to ensure mathematical stability.

Returns

float

The calculated initial jump velocity required to reach the target height.

CalculateLaunchVelocity(double, double, double, double)

Calculates the required initial velocity along a single axis to reach a target displacement in a given time under constant acceleration.

public static double CalculateLaunchVelocity(double target, double start, double g, double t)

Parameters

target double

The target position to reach.

start double

The starting position.

g double

The constant acceleration along this axis (e.g., gravity).

t double

The desired time to reach the target in seconds.

Returns

double

The required initial velocity, or zero if t is zero.

CalculateLaunchVelocity(float, float, float, float)

Calculates the required initial velocity along a single axis to reach a target displacement in a given time under constant acceleration.

public static float CalculateLaunchVelocity(float target, float start, float g, float t)

Parameters

target float

The target position to reach.

start float

The starting position.

g float

The constant acceleration along this axis (e.g., gravity).

t float

The desired time to reach the target in seconds.

Returns

float

The required initial velocity, or zero if t is zero.

CalculateTimeToApex(double, double)

Calculates the time required for a projectile to reach the apex (highest point) of its trajectory under constant gravity.

public static double CalculateTimeToApex(double velocityY, double gravity)

Parameters

velocityY double

The initial vertical velocity vector component.

gravity double

The acceleration due to gravity. Its absolute value is used to prevent negative time results.

Returns

double

The calculated time to reach the maximum height in seconds.

CalculateTimeToApex(float, float)

Calculates the time required for a projectile to reach the apex (highest point) of its trajectory under constant gravity.

public static float CalculateTimeToApex(float velocityY, float gravity)

Parameters

velocityY float

The initial vertical velocity vector component.

gravity float

The acceleration due to gravity. Its absolute value is used to prevent negative time results.

Returns

float

The calculated time to reach the maximum height in seconds.

ClampVelocity(double, double)

Clamps a velocity value to be within a symmetric range defined by a maximum speed limit.

public static double ClampVelocity(double v, double max)

Parameters

v double

The current velocity to clamp.

max double

The maximum allowed speed (magnitude), which will be used to define both upper and lower bounds.

Returns

double

The clamped velocity, constrained between -abs(max) and abs(max).

ClampVelocity(float, float)

Clamps a velocity value to be within a symmetric range defined by a maximum speed limit.

public static float ClampVelocity(float v, float max)

Parameters

v float

The current velocity to clamp.

max float

The maximum allowed speed (magnitude), which will be used to define both upper and lower bounds.

Returns

float

The clamped velocity, constrained between -abs(max) and abs(max).

Drag(double, double, double, double, double)

Applies linear drag to 3D velocity components over a given time step, stopping the movement along XY if the 3D velocity magnitude drops below a small threshold.

public static (double x, double y, double z) Drag(double velocityX, double velocityY, double velocityZ, double drag, double deltaTime)

Parameters

velocityX double

The X component of the velocity.

velocityY double

The Y component of the velocity.

velocityZ double

The Z component of the velocity.

drag double

The drag coefficient influencing the exponential decay speed.

deltaTime double

The time elapsed since the last frame in seconds.

Returns

(double x, double y, double z)

A tuple containing the updated X and Y velocity components, or zeros if the total 3D speed is below the threshold.

Drag(Vector3, float, float)

Applies linear drag to a 3D velocity vector over a given time step, stopping the object completely if its speed drops below a small threshold.

public static Vector3 Drag(Vector3 velocity, float drag, float deltaTime)

Parameters

velocity Vector3

The current velocity vector.

drag float

The drag coefficient (typically negative to slow the object down, or positive depending on the expected math convention).

deltaTime float

The time elapsed since the last frame in seconds.

Returns

Vector3

The updated velocity vector after drag has been applied, or Zero if the squared velocity is below 0.0001f.

Drag(float, float, float, float, float)

Applies linear drag to 3D velocity components over a given time step, stopping the movement along XY if the 3D velocity magnitude drops below a small threshold.

public static (float x, float y, float z) Drag(float velocityX, float velocityY, float velocityZ, float drag, float deltaTime)

Parameters

velocityX float

The X component of the velocity.

velocityY float

The Y component of the velocity.

velocityZ float

The Z component of the velocity.

drag float

The drag coefficient influencing the exponential decay speed.

deltaTime float

The time elapsed since the last frame in seconds.

Returns

(float x, float y, float z)

A tuple containing the updated X and Y velocity components, or zeros if the total 3D speed is below the threshold.

GetStoppingDistance(double, double)

Calculates the stopping distance required for an object to come to a complete stop from a given velocity under constant deceleration.

public static double GetStoppingDistance(double v, double a)

Parameters

v double

The current velocity of the object.

a double

The constant deceleration rate (magnitude of acceleration slowing the object down).

Returns

double

The calculated stopping distance, or zero if the deceleration is zero.

GetStoppingDistance(float, float)

Calculates the stopping distance required for an object to come to a complete stop from a given velocity under constant deceleration.

public static float GetStoppingDistance(float v, float a)

Parameters

v float

The current velocity of the object.

a float

The constant deceleration rate (magnitude of acceleration slowing the object down).

Returns

float

The calculated stopping distance, or zero if the deceleration is zero.

JumpCut(double, double)

Reduces upward velocity when a jump button is released early, commonly used for variable jump heights in platformers.

public static double JumpCut(double v, double multiplier)

Parameters

v double

The current vertical velocity.

multiplier double

The factor by which to multiply the velocity (usually between 0.0 and 1.0).

Returns

double

The modified velocity if moving upward (greater than 0), otherwise the original velocity.

JumpCut(float, float)

Reduces upward velocity when a jump button is released early, commonly used for variable jump heights in platformers.

public static float JumpCut(float v, float multiplier)

Parameters

v float

The current vertical velocity.

multiplier float

The factor by which to multiply the velocity (usually between 0.0 and 1.0).

Returns

float

The modified velocity if moving upward (greater than 0), otherwise the original velocity.

MoveTowards(double, double, double)

Moves a value toward a target value by a maximum specified delta.

public static double MoveTowards(double current, double target, double maxDelta)

Parameters

current double

The current value.

target double

The value to move towards.

maxDelta double

The maximum amount by which the value can change.

Returns

double

The new value closer to the target, or the target itself if it is within range.

MoveTowards(float, float, float)

Moves a value toward a target value by a maximum specified delta.

public static float MoveTowards(float current, float target, float maxDelta)

Parameters

current float

The current value.

target float

The value to move towards.

maxDelta float

The maximum amount by which the value can change.

Returns

float

The new value closer to the target, or the target itself if it is within range.

PredictTrajectory(Vector2, Vector2, Vector2, float)

Predicts the 2D position of a projectile at a given time under constant acceleration (gravity).

public static Vector2 PredictTrajectory(Vector2 startPos, Vector2 startVelocity, Vector2 gravity, float t)

Parameters

startPos Vector2

The initial position vector.

startVelocity Vector2

The initial velocity vector.

gravity Vector2

The acceleration vector (such as gravity).

t float

The time elapsed since the start of the trajectory in seconds.

Returns

Vector2

The calculated Vector2 position at time t.

PredictTrajectory(float, float, float, float, float, float, float)

Predicts the 2D position coordinates of a projectile at a given time under constant acceleration (gravity).

public static (float x, float y) PredictTrajectory(float startPosX, float startPosY, float startVelocityX, float startVelocityY, float gravityX, float gravityY, float t)

Parameters

startPosX float

The initial X-coordinate position.

startPosY float

The initial Y-coordinate position.

startVelocityX float

The initial velocity along the X-axis.

startVelocityY float

The initial velocity along the Y-axis.

gravityX float

The acceleration along the X-axis.

gravityY float

The acceleration along the Y-axis.

t float

The time elapsed since the start of the trajectory in seconds.

Returns

(float x, float y)

A tuple containing the calculated X and Y position coordinates at time t.

TerminalVelocity(double, double)

Caps falling velocity to prevent an object from exceeding a maximum downward terminal velocity limit.

public static double TerminalVelocity(double v, double vlimit)

Parameters

v double

The current vertical velocity (negative values represent falling).

vlimit double

The maximum allowed falling speed magnitude (should be positive).

Returns

double

The clamped velocity, restricted so that it does not drop below -vlimit.

TerminalVelocity(float, float)

Caps falling velocity to prevent an object from exceeding a maximum downward terminal velocity limit.

public static float TerminalVelocity(float v, float vlimit)

Parameters

v float

The current vertical velocity (negative values represent falling).

vlimit float

The maximum allowed falling speed magnitude (should be positive).

Returns

float

The clamped velocity, restricted so that it does not drop below -vlimit.