void ApplyForceAt( Vector3& position, Vector3& force )

book_4_sparkGenerated
code_blocksInput

Description

The ApplyForceAt method applies a force to the Rigidbody at a specified position. This method is useful for simulating realistic physical interactions, such as applying a force at a specific point on an object to cause it to rotate or move in a particular direction.

Usage

To use the ApplyForceAt method, you need to provide two parameters:

  • position: A reference to a Vector3 that specifies the world position where the force should be applied.
  • force: A reference to a Vector3 that specifies the direction and magnitude of the force to be applied.

Ensure that the Rigidbody component is attached to a GameObject with a collider for the physics interactions to take effect.

Example

// Example of applying a force at a specific position on a Rigidbody
Rigidbody myRigidbody = new Rigidbody();
Vector3 position = new Vector3(1.0f, 0.0f, 0.0f); // Position where the force is applied
Vector3 force = new Vector3(0.0f, 10.0f, 0.0f);   // Force vector

myRigidbody.ApplyForceAt(ref position, ref force);