Rigidbody Class
Properties
Mass
: The mass of the rigidbody. Determines the resistance to acceleration and force applied to the object.Velocity
: The current velocity of the rigidbody.Acceleration
: The current acceleration of the rigidbody.IsKinematic
: Indicates whether the rigidbody is affected by external forces or controlled manually.
Methods
ApplyForce(Vector2Int force)
: Applies a force to the rigidbody, affecting its acceleration and velocity.ApplyImpulse(Vector2Int impulse)
: Applies an impulse to the rigidbody, changing its velocity instantly.AddForce(Vector2Int force)
: Adds a force to the current force being applied to the rigidbody.AddImpulse(Vector2Int impulse)
: Adds an impulse to the current impulse being applied to the rigidbody.Stop()
: Stops the rigidbody's motion by setting its velocity and acceleration to zero.Update()
: Updates the rigidbody's position based on its velocity and applies any ongoing forces.
Example Usage
// Create a game object with a rigidbody
GameObject gameObject = new GameObject(new Vector2Int(0, 0), "MyObject");
Rigidbody rigidbody = gameObject.AddComponent();
// Set rigidbody properties
rigidbody.Mass = 1f;
rigidbody.IsKinematic = false;
// Apply forces to the rigidbody
Vector2Int force = new Vector2Int(5f, 0f);
rigidbody.ApplyForce(force);