AddForceAtPosition(Vector3, Vector3, ForceMode)
Applies force at position. As a result this will apply a torque and force on the object.
Read time 1 minuteLast updated 10 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.PhysicsModule
public void AddForceAtPosition(Vector3 force, Vector3 position, ForceMode mode)
Parameters
Remarks
For realistic effects should be approximately in the range of the surface of the rigidbody. This is most commonly used for explosions. When applying explosions it is best to apply forces over several frames instead of just one. Note that when is far away from the center of the rigidbody the applied torque will be unrealistically large.
positionpositionForce can be applied only to an active rigidbody. If a GameObject is inactive, AddForceAtPosition has no effect.
Wakes up the Rigidbody by default. If the force size is zero then the Rigidbody will not be woken up.
For more information on how ForceMode affects velocity, see Rigidbody.AddForce.
Note: If you are using or , the force applied by is scaled by the world-space inertia tensor matrix.
ForceMode.AccelerationForceMode.VelocityChangeAddForceAtPositionAdditional Resources: Rigidbody.AddForce, Rigidbody.AddRelativeForce, Rigidbody.AddTorque, _inertiaTensor
Examples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ void ApplyForce(Rigidbody body) { Vector3 direction = body.transform.position - transform.position; body.AddForceAtPosition(direction.normalized, transform.position); }}