void ApplyForce( Vector3& force )

book_4_sparkGenerated
code_blocksInput

Description

The ApplyForce method applies a linear force to the Rigidbody component. This method is used to influence the motion of the object by applying a force vector, which can affect the velocity and direction of the object.

Usage

To use the ApplyForce method, you need to have a Rigidbody component attached to your game object. You can then call this method and pass a Vector3 reference representing the force you want to apply. The force vector should be in world coordinates.

Example

// Example of applying a force to a Rigidbody
Rigidbody myRigidbody = GetComponent<Rigidbody>();
Vector3 force = new Vector3(0, 10, 0); // Apply an upward force
myRigidbody.ApplyForce(ref force);