Rigidbody.AddForceAtPosition 在位置上添加力

function AddForceAtPosition (force : Vector3, position : Vector3, mode : ForceMode = ForceMode.Force) : void

Description描述

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

在position位置应用force力。作为结果这个将在这个物体上应用一个力矩和力。

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.

对于真实的效果,位置应大约在刚体表面的范围。这个最常用于爆炸,当应用于爆炸时,最好应用力到多帧而不是一帧中。注意当position远离刚体的中心时,所应用的力矩会不切实际地大。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void ApplyForce(Rigidbody body) {
		Vector3 direction = body.transform.position - transform.position;
		body.AddForceAtPosition(direction.normalized, transform.position);
	}
}
function ApplyForce (body : Rigidbody) {
	var direction : Vector3 = body.transform.position - transform.position;
	body.AddForceAtPosition(direction.normalized, transform.position);
}
最后修改:2011年2月9日 Wednesday 21:08

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。