Skip to content

Rigidbody2D Extensions

Andrzej Kebab edited this page Feb 2, 2024 · 5 revisions

UtilityLibrary.Unity.Runtime

Momentum Control

ClearMomentum

Clears the momentum of the Rigidbody2D instance.

rigidbody.ClearMomentum();

Position Control

Set Position

SetPositionX

Sets the x position of the Rigidbody2D instance.

rigidbody.SetPositionX(2.0f);

Parameters:

  • {float} x: The x position.

SetPositionY

Sets the y position of the Rigidbody2D instance.

rigidbody.SetPositionY(3.0f);

Parameters:

  • {float} y: The y position.

Get Position

GetPositionX

Gets the x position of the Rigidbody2D instance.

float xPos = rigidbody.GetPositionX();

Returns:

  • {float}: The x position.

GetPositionY

Gets the y position of the Rigidbody2D instance.

float yPos = rigidbody.GetPositionY();

Parameters:

  • {Rigidbody2D} rigidbody: The Rigidbody2D instance.

Returns:

  • {float}: The y position.

Velocity Control

Set Velocity

SetVelocityX

Sets the x velocity of the Rigidbody2D instance.

rigidbody.SetVelocityX(5.0f);

Parameters:

  • {float} x: The x velocity.

SetVelocityY

Sets the y velocity of the Rigidbody2D instance.

rigidbody.SetVelocityY(-2.0f);

Parameters:

  • {float} y: The y velocity.

Get Velocity

GetVelocityX

Gets the x velocity of the Rigidbody2D instance.

float xVel = rigidbody.GetVelocityX();

Returns:

  • {float}: The x velocity.

GetVelocityY

Gets the y velocity of the Rigidbody2D instance.

float yVel = rigidbody.GetVelocityY();

Parameters:

  • {Rigidbody2D} rigidbody: The Rigidbody2D instance.

Returns:

  • {float}: The y velocity.

Add Velocity

AddVelocityX

Adds to the x velocity of the Rigidbody2D instance.

rigidbody.AddVelocityX(2.0f);

Parameters:

  • {float} x: The x velocity to add.

AddVelocityY

Adds to the y velocity of the Rigidbody2D instance.

rigidbody.AddVelocityY(-1.0f);

Parameters:

  • {float} y: The y velocity to add.

Clone this wiki locally