Language: English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Rigidbody.AddForceAtPosition

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public function AddForceAtPosition(force: Vector3, position: Vector3, mode: ForceMode = ForceMode.Force): void;
public void AddForceAtPosition(Vector3 force, Vector3 position, ForceMode mode = ForceMode.Force);

Parameters

forceIn world coordinate system.
positionIn world coordinate system.

Description

Applies force at position. As a result this will apply a torque and force on the object.

For realistic effects position 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 position is far away from the center of the rigidbody the applied torque will be unrealistically large.

Force can be applied only to an active rigidbody. If a GameObject is inactive, AddForceAtPosition has no effect.

See Also: AddForce, AddRelativeForce, AddTorque.

	function ApplyForce (body : Rigidbody) {
		var direction : Vector3 = body.transform.position - transform.position;
		body.AddForceAtPosition(direction.normalized, transform.position);
	}
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); } }