Skip to content

Rigidbody Extensions

Andrzej Kebab edited this page Feb 2, 2024 · 1 revision

UtilityLibrary.Unity.Runtime

Momentum Control

ClearMomentum

Clears the momentum of the Rigidbody instance.

// Example of usage
rigidbody.ClearMomentum();

Parameters:

  • {Rigidbody} rigidbody: The Rigidbody instance.

Returns:

  • void

Position Control

Set Position

SetPositionX

Sets the x position of the Rigidbody instance.

// Example of usage
rigidbody.SetPositionX(2.0f);

SetPositionY

Sets the y position of the Rigidbody instance.

// Example of usage
rigidbody.SetPositionY(3.0f);

SetPositionZ

Sets the z position of the Rigidbody instance.

// Example of usage
rigidbody.SetPositionZ(4.0f);

Parameters:

  • {float} x: The x position.
  • {float} y: The y position.
  • {float} z: The z position.

Returns:

  • void

Get Position

GetPositionX

Gets the x position of the Rigidbody instance.

// Example of usage
float xPos = rigidbody.GetPositionX();

GetPositionY

Gets the y position of the Rigidbody instance.

// Example of usage
float yPos = rigidbody.GetPositionY();

GetPositionZ

Gets the z position of the Rigidbody instance.

// Example of usage
float zPos = rigidbody.GetPositionZ();

Parameters:

  • {Rigidbody} rigidbody: The Rigidbody instance.

Returns:

  • {float}: The x, y, or z position.

Rotation Control

Get Rotation

GetRotationX

Gets the x rotation of the Rigidbody instance.

// Example of usage
float xRot = rigidbody.GetRotationX();

GetRotationY

Gets the y rotation of the Rigidbody instance.

// Example of usage
float yRot = rigidbody.GetRotationY();

GetRotationZ

Gets the z rotation of the Rigidbody instance.

// Example of usage
float zRot = rigidbody.GetRotationZ();

GetRotationW

Gets the w rotation of the Rigidbody instance.

// Example of usage
float wRot = rigidbody.GetRotationW();

Parameters:

  • {Rigidbody} rigidbody: The Rigidbody instance.

Returns:

  • {float}: The x, y, z, or w rotation.

Set Rotation

SetRotationX

Sets the x rotation of the Rigidbody instance.

// Example of usage
rigidbody.SetRotationX(45.0f);

SetRotationY

Sets the y rotation of the Rigidbody instance.

// Example of usage
rigidbody.SetRotationY(90.0f);

SetRotationZ

Sets the z rotation of the Rigidbody instance.

// Example of usage
rigidbody.SetRotationZ(180.0f);

SetRotationW

Sets the w rotation of the Rigidbody instance.

// Example of usage
rigidbody.SetRotationW(1.0f);

Parameters:

  • {float} x: The x rotation.
  • {float} y: The y rotation.
  • {float} z: The z rotation.
  • {float} w: The w rotation.

Returns:

  • void

Euler Angles Control

Set EulerAngles

SetEulerAnglesX

Sets the x component of the Euler angles of the Rigidbody instance.

// Example of usage
rigidbody.SetEulerAnglesX(45.0f);

SetEulerAnglesY

Sets the y component of the Euler angles of the Rigidbody instance.

// Example of usage
rigidbody.SetEulerAnglesY(90.0f);

SetEulerAnglesZ

Sets the z component of the Euler angles of the Rigidbody instance.

// Example of usage
rigidbody.SetEulerAnglesZ(180.0f);

Parameters:

  • {float} x: The x component of the Euler angles.
  • {float} y: The y component of the Euler angles.
  • {float} z: The z component of the Euler angles.

Returns:

  • void

Get EulerAngles

GetEulerAnglesX

Gets the x component of the Euler angles of the Rigidbody instance.

// Example of usage
float xEuler = rigidbody.GetEulerAnglesX();

GetEulerAnglesY

Gets the y component of the Euler

angles of the Rigidbody instance.

// Example of usage
float yEuler = rigidbody.GetEulerAnglesY();

GetEulerAnglesZ

Gets the z component of the Euler angles of the Rigidbody instance.

// Example of usage
float zEuler = rigidbody.GetEulerAnglesZ();

Parameters:

  • {Rigidbody} rigidbody: The Rigidbody instance.

Returns:

  • {float}: The x, y, or z component of the Euler angles.

Velocity Control

Set Velocity

SetVelocityX

Sets the x component of the velocity of the Rigidbody instance.

// Example of usage
rigidbody.SetVelocityX(5.0f);

SetVelocityY

Sets the y component of the velocity of the Rigidbody instance.

// Example of usage
rigidbody.SetVelocityY(-2.0f);

SetVelocityZ

Sets the z component of the velocity of the Rigidbody instance.

// Example of usage
rigidbody.SetVelocityZ(3.0f);

Parameters:

  • {float} x: The x component of the velocity.
  • {float} y: The y component of the velocity.
  • {float} z: The z component of the velocity.

Returns:

  • void

Get Velocity

GetVelocityX

Gets the x component of the velocity of the Rigidbody instance.

// Example of usage
float xVel = rigidbody.GetVelocityX();

GetVelocityY

Gets the y component of the velocity of the Rigidbody instance.

// Example of usage
float yVel = rigidbody.GetVelocityY();

GetVelocityZ

Gets the z component of the velocity of the Rigidbody instance.

// Example of usage
float zVel = rigidbody.GetVelocityZ();

Parameters:

  • {Rigidbody} rigidbody: The Rigidbody instance.

Returns:

  • {float}: The x, y, or z component of the velocity.

Add Velocity

AddVelocityX

Adds to the x component of the velocity of the Rigidbody instance.

// Example of usage
rigidbody.AddVelocityX(2.0f);

AddVelocityY

Adds to the y component of the velocity of the Rigidbody instance.

// Example of usage
rigidbody.AddVelocityY(-1.0f);

AddVelocityZ

Adds to the z component of the velocity of the Rigidbody instance.

// Example of usage
rigidbody.AddVelocityZ(0.5f);

Parameters:

  • {float} x: The x component to add to the velocity.
  • {float} y: The y component to add to the velocity.
  • {float} z: The z component to add to the velocity.

Returns:

  • void

Angular Velocity Control

Set Angular Velocity

SetAngularVelocityX

Sets the x component of the angular velocity of the Rigidbody instance.

// Example of usage
rigidbody.SetAngularVelocityX(90.0f);

SetAngularVelocityY

Sets the y component of the angular velocity of the Rigidbody instance.

// Example of usage
rigidbody.SetAngularVelocityY(-45.0f);

SetAngularVelocityZ

Sets the z component of the angular velocity of the Rigidbody instance.

// Example of usage
rigidbody.SetAngularVelocityZ(180.0f);

Parameters:

  • {float} x: The x component of the angular velocity.
  • {float} y: The y component of the angular velocity.
  • {float} z: The z component of the angular velocity.

Returns:

  • void

Get Angular Velocity

GetAngularVelocityX

Gets the x component of the angular velocity of the Rigidbody instance.

// Example of usage
float xAngVel = rigidbody.GetAngularVelocityX();

GetAngularVelocityY

Gets the y component of the angular velocity of the Rigidbody instance.

// Example of usage
float yAngVel = rigidbody.GetAngularVelocityY();

GetAngularVelocityZ

Gets the z component of the angular velocity of the Rigidbody instance.

// Example of usage
float zAngVel = rigidbody.GetAngularVelocityZ();

Parameters:

  • {Rigidbody} rigidbody: The Rigidbody instance.

Returns:

  • {float}: The x, y, or z component of the angular velocity.

Add Angular Velocity

AddAngularVelocityX

Adds to the x component of the angular velocity of the Rigidbody instance.

// Example of usage
rigidbody.AddAngularVelocityX(20.0f);

AddAngularVelocityY

Adds to the y component of the angular velocity of the Rigidbody instance.

// Example of usage
rigidbody.AddAngularVelocityY(-10.0f);

AddAngularVelocityZ

Adds to the z component of the angular velocity of the Rigidbody instance.

// Example of usage
rigidbody.AddAngularVelocityZ(5.0f);

Parameters:

  • {float} x: The x component to add to the angular velocity.
  • {float} y: The y component to add to the angular velocity.
  • {float} z: The z component to add to the angular velocity.

Clone this wiki locally