Version: 5.5
public static Vector3 RotateTowards (Vector3 current, Vector3 target, float maxRadiansDelta, float maxMagnitudeDelta);

説明

現在の位置 current から target に向けてベクトルを回転します。

この関数はベクトルが位置ではなく方向として扱われることを除き MoveTowards 関数に似ています。 現在の位置 current のベクトルは、 目的地を通り過ぎるのではなく maxRadiansDelta のアングルで target の方へ円を描くように回転します。 現在の位置 currenttarget の magnitude の値が異なっている場合、結果の magnitude の値が回転中に線形補間されます。 負の値を maxRadiansDelta に使用する場合、ベクトルは正確に反対方向を指すまで target から離れて回転し、停止します。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Transform target; public float speed; void Update() { Vector3 targetDir = target.position - transform.position; float step = speed * Time.deltaTime; Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0F); Debug.DrawRay(transform.position, newDir, Color.red); transform.rotation = Quaternion.LookRotation(newDir); } }