ForceMode:
Force:关注的是力整体
Impulse:关注的是冲量,与质量相关
VelocityChange:关注的是速度,与质量无关
Acceleration:关注的是加速度,与质量无关
public void AddForce(Vector3 force, [Internal.DefaultValue("ForceMode.Force")] ForceMode mode);
扭矩:AddTorque(ForceMode同上)
public void AddTorque(Vector3 torque, [Internal.DefaultValue("ForceMode.Force")] ForceMode mode);
如:
public class AddForceTest : MonoBehaviour
{
private Rigidbody rd;
// Start is called before the first frame update
void Start()
{
//rd.AddForce(new Vector3(0,0,10),ForceMode.Force);
//rd.AddForce(new Vector3(0,0,10),ForceMode.Acceleration);
rd.AddTorque(Vector3.forward);
}
}
AddForce与AddRelativeForce的区别:
AddRelativeForce是以自身坐标系来进行移动的,比如:
我把cube绕Y轴旋转了一定角度
使用:(注Vector3.forward是定值为(0,0,1))
public class AddRelativeForceTest : MonoBehaviour
{
Rigidbody ts;
// Start is called before the first frame update
void Start()
{
ts=GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
ts.AddRelativeForce(Vector3.forward);
//ts.AddForce(Vector3.forward);
}
}
则cube沿自身z轴方向移动
使用:
public class AddRelativeForceTest : MonoBehaviour
{
Rigidbody ts;
// Start is called before the first frame update
void Start()
{
ts=GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
//ts.AddRelativeForce(Vector3.forward);
ts.AddForce(Vector3.forward);
}
}
cube沿世界坐标系的z轴移动。