29
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

2点の座標と角度の中間を求める

Last updated at Posted at 2015-11-06

Vector3.Lerp と Quaternion.Lerp が便利

BlendedPosition.cs
using UnityEngine;
using System.Collections;

public class BlendedPosition : MonoBehaviour
{
    [SerializeField] private Transform a;
    [SerializeField] private Transform b;

    void Start ()
    {

    }

    void Update ()
    {
        transform.position = Vector3.Lerp(a.position, b.position, 0.5f);
        transform.rotation = Quaternion.Lerp(a.rotation, b.rotation, 0.5f);
    }
}

追記:2015/11/08

そもそも2点間の中間をもとめるには、補間方法が違う Lerp と Slerp があります。
http://docs.unity3d.com/jp/current/ScriptReference/Vector3.Lerp.html
http://docs.unity3d.com/jp/current/ScriptReference/Vector3.Slerp.html

パフォーマンスと精度に違いあるようですが、試してないので不明です。
http://forum.unity3d.com/threads/what-is-the-difference-of-quaternion-slerp-and-lerp.101179/

補間の違いについては下記コメントの @Ushio@github さんのコードがすごく分かりやすいです。

29
21
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
29
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?