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

参数

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

描述

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).

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).

另请参阅:AddForceAtPositionAddRelativeForceAddTorque

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); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961