facebook twitter hatena line email

「Unity/Csharp/位置」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(指定場所へ徐々に移動)
(指定場所へ徐々に移動)
行55: 行55:
 
返されるpositionは、少し移動した座標となる
 
返されるpositionは、少し移動した座標となる
 
<pre>
 
<pre>
Vector startPosition = new Vector(1f, 0f, 0f);
+
Vector3 startPosition = new Vector(1f, 0f, 0f);
Vector endPosition = new Vector(1f, 1f, 1f);
+
Vector3 endPosition = new Vector(1f, 1f, 1f);
 
float speed = 2f;
 
float speed = 2f;
 
float step = speed * Time.deltaTime;
 
float step = speed * Time.deltaTime;

2024年7月13日 (土) 04:56時点における版

中間位置

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

指定場所へ徐々に移動

返されるpositionは、少し移動した座標となる

Vector3 startPosition = new Vector(1f, 0f, 0f);
Vector3 endPosition = new Vector(1f, 1f, 1f);
float speed = 2f;
float step = speed * Time.deltaTime;
Vector3 position = Vector3.MoveTowards(
                    startPosition,
                    endPosition,
                    step
                );

参考:https://docs.unity3d.com/ja/560/ScriptReference/Vector3.MoveTowards.html