「Unity/Csharp/位置」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→方向) |
(→方向) |
||
行50: | 行50: | ||
Vector3(0, 0, -1) | Vector3(0, 0, -1) | ||
Vector3.back | Vector3.back | ||
+ | </pre> | ||
+ | |||
+ | ==指定場所へ徐々に移動== | ||
+ | <pre> | ||
+ | Vector startPosition = new Vector(1f, 0f, 0f); | ||
+ | Vector endPosition = new Vector(1f, 1f, 1f); | ||
+ | float speed = 2f; | ||
+ | Vector3 position = Vector3.MoveTowards( | ||
+ | startPosition, | ||
+ | endPosition, | ||
+ | speed | ||
+ | ); | ||
</pre> | </pre> |
2024年7月12日 (金) 12:28時点における版
中間位置
Vector3 center = Vector3.Lerp(fromObj, toObj, 0.5f);
3dの回転
Unity/3d/回転 [ショートカット]
方向
以下それぞれ2つは同じ意味
new Vector3(0f, 0f, 0f) Vector3.zero
new Vector3(1f, 1f, 1f) Vector3.one
new Vector3(2f, 2f, 2f) Vector3.one * 2;
new Vector3(0, 1, 0) Vector3.up
Vector3(0, -1, 0) Vector3.down
Vector3(1, 0, 0) Vector3.right
Vector3(-1, 0, 0) Vector3.left
Vector3(0, 0, 1) Vector3.forward
Vector3(0, 0, -1) Vector3.back
指定場所へ徐々に移動
Vector startPosition = new Vector(1f, 0f, 0f); Vector endPosition = new Vector(1f, 1f, 1f); float speed = 2f; Vector3 position = Vector3.MoveTowards( startPosition, endPosition, speed );