Skip to content

Instantly share code, notes, and snippets.

@aidiary
Last active October 11, 2018 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aidiary/7937ba6b6c5762efa021 to your computer and use it in GitHub Desktop.
Save aidiary/7937ba6b6c5762efa021 to your computer and use it in GitHub Desktop.
Rigidbody.AddForce()のオプションの違いを調べる
#pragma strict
// Rigidbody.AddForce()のオプションの違い
// 参考: http://d.hatena.ne.jp/nakamura001/20120320/1332224186
var bigCube : GameObject;
var bigCubeStartPos : Vector3;
var bigCubeStartRot : Quaternion;
var smallCube : GameObject;
var smallCubeStartPos : Vector3;
var smallCubeStartRot : Quaternion;
function Start () {
// 初期配置を記憶
bigCubeStartPos = bigCube.transform.position;
bigCubeStartRot = bigCube.transform.rotation;
smallCubeStartPos = smallCube.transform.position;
smallCubeStartRot = smallCube.transform.rotation;
bigCube.rigidbody.Sleep();
smallCube.rigidbody.Sleep();
}
function Update () {
}
function OnGUI() {
GUI.Box(new Rect(10, 10, 140, 180), "Menu");
// 初期化ボタン
if (GUI.Button(new Rect(20, 40, 120, 20), "Reset")) {
bigCube.rigidbody.Sleep();
smallCube.rigidbody.Sleep();
bigCube.transform.position = bigCubeStartPos;
bigCube.transform.rotation = bigCubeStartRot;
smallCube.transform.position = smallCubeStartPos;
smallCube.transform.rotation = smallCubeStartRot;
}
// Force(質量が反映する、連続的な力を加える)
if (GUI.Button(new Rect(20, 70, 120, 20), "Force")) {
bigCube.rigidbody.AddForce(Vector3.right * 200, ForceMode.Force);
smallCube.rigidbody.AddForce(Vector3.right * 200, ForceMode.Force);
}
// Acceleration(質量を考慮しない、連続的な加速を加える)
if (GUI.Button(new Rect(20, 100, 120, 20), "Acceleration")) {
bigCube.rigidbody.AddForce(Vector3.right * 200, ForceMode.Acceleration);
smallCube.rigidbody.AddForce(Vector3.right * 200, ForceMode.Acceleration);
}
// Impulse(質量が反映する、瞬間的な力を加える)
if (GUI.Button(new Rect(20, 130, 120, 20), "Impulse")) {
bigCube.rigidbody.AddForce(Vector3.right * 10, ForceMode.Impulse);
smallCube.rigidbody.AddForce(Vector3.right * 10, ForceMode.Impulse);
}
// VelocityChange(質量を考慮しない、連続的な速度の変化を加える)
if (GUI.Button(new Rect(20, 160, 120, 20), "VelocityChange")) {
bigCube.rigidbody.AddForce(Vector3.right * 10, ForceMode.VelocityChange);
smallCube.rigidbody.AddForce(Vector3.right * 10, ForceMode.VelocityChange);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment