オブジェクトに力を加える

GameObjectのcubeに、(x,y,z)の力を加える
cube.transform.GetComponent<Rigidbody>().AddForce(new Vector3(nx, ny, nz));

ジャンプ威力
public float jumpPower = 3.0f;
private Rigidbody rb;
重力の影響あり
rb.useGravity = true;
rb.AddForce(Vector3.up * jumpPower, ForceMode.VelocityChange);

ForceMode一覧
Force      質量を考慮して継続的に力を加える
Acceleration  質量を無視して力を加える
Impulse  質量を考慮して瞬時に力を加える(力積を加える)
VelocityChange 質量を無視して瞬時に力を加える(速度を変える)


オブジェクトが向いている方向に力を加える
this.GetComponent<Rigidbody>().AddForce(transform.forward*1000);
transform.forwardがthisが向いている方向

タグ:

unity
最終更新:2015年04月01日 23:35