Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


AddForceAtPosition(Vector2, Vector2, ForceMode2D)

Apply a force at a given position in space.
Read time 1 minuteLast updated 4 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.Physics2DModule
public void AddForceAtPosition(Vector2 force, Vector2 position, ForceMode2D mode)

Parameters

force

Components of the force in the X and Y axes.

position

Position in world space to apply the force.

The method used to apply the specified force.

Remarks

The Rigidbody2D.AddForce function applies a force that acts straight through the rigidbody's centre of mass and so produces only positional movement and no rotation. AddForceAtPosition can apply the force at any position in world space and will typically also apply a torque to the object which will set it rotating. Note that for the purposes of this function, the rigidbody is just a coordinate space of infinite size, so there is no reason why the force needs to be applied within the confines of the object's graphic or colliders.