21
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

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

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 さんのコードがすごく分かりやすいです。

Register as a new user and use Qiita more conveniently

  1. You can follow users and tags
  2. you can stock useful information
  3. You can make editorial suggestions for articles
What you can do with signing up
21
Help us understand the problem. What are the problem?