Version: 2021.2
LanguageEnglish
  • C#

ArticulationBody.AddForce

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

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> 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

Declaration

public void AddForce(Vector3 force, ForceMode mode = ForceMode.Force);

Parameters

force The force vector to apply.
mode The type of force to apply.

Description

Applies a force to the ArticulationBody.

Note that the force accumulates over the duration of a simulation frame. It is only physically applied to the articulation body during the simulation step, after FixedUpdate has been called to scripts. Specifying the ForceMode mode allows the type of force to be changed to an Acceleration, Impulse or Velocity Change.

You can only apply a force to an active ArticulationBody. If a GameObject is inactive, AddForce has no effect. Also, the ArticulationBody must be movable (cannot be immovable).

For more information on how ForceMode affects velocity, see Rigidbody.AddForce.

By default the ArticulationBody's state is set to awake when a force is applied, unless the force is Vector3.zero.
Unit of measurement - N (newtons).

See Also: AddForceAtPosition, AddRelativeForce, AddTorque.

This example applies a forward force to the GameObject's ArticulationBody.

using UnityEngine;

public class Example : MonoBehaviour { ArticulationBody m_ArticulationBody; public float m_Thrust = 20f;

void Start() { //Fetch the ArticulationBody from the GameObject with this script attached m_ArticulationBody = GetComponent<ArticulationBody>(); }

void FixedUpdate() { if (Input.GetButton("Jump")) { //Apply a force to this ArticulationBody in the direction of this GameObject's up-axis m_ArticulationBody.AddForce(transform.up * m_Thrust); } } }