Rigidbody.AddForceAtPosition

매뉴얼로 전환
public void AddForceAtPosition (Vector3 force, Vector3 position, ForceMode mode= ForceMode.Force);

파라미터

forceForce vector in world coordinates.
positionPosition in world coordinates.

설명

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.

Wakes up the Rigidbody by default. If the force size is zero then the Rigidbody will not be woken up.

See Also: AddForce, AddRelativeForce, AddTorque.

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