Unity/3d/ゆっくり移動
提供: 初心者エンジニアの簡易メモ
Leapを使ってゆっくり移動を
presentには0〜1を入れる。
float present = 0f; // 0~1 [SerializeField] GameObject startObj; [SerializeField] GameObject endObj; [SerializeField] GameObject nowObj; void Update() { present += 0.01f; nowObj.transform.localPosition = Vector3.Lerp(startObj.transform.localPosition, endObj.transform.localPosition, present); }
Sleapを使って球状にゆっくり移動を
presentには0〜1を入れる。
[SerializeField] GameObject startObj; [SerializeField] GameObject endObj; [SerializeField] GameObject nowObj; void Update() { float distance = Vector3.Distance(startObj.transform.localPosition, endObj.transform.localPosition); float present = (Time.time * speed) / distance/ 10; nowObj.transform.localPosition = Vector3.Slerp(startObj.transform.localPosition, endObj.transform.localPosition, present); }