Version: 5.4 (switch to 5.5b)

• C#
• JS

## Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

# Vector3.RotateTowards

Suggest a change

## Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

## Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close
マニュアルに切り替える
public static function RotateTowards(current: Vector3, target: Vector3, maxRadiansDelta: float, maxMagnitudeDelta: float): Vector3;
public static Vector3 RotateTowards(Vector3 current, Vector3 target, float maxRadiansDelta, float maxMagnitudeDelta);

## Description

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

```	// The target marker.
var target: Transform;

// Angular speed in radians per sec.
var speed: float;

function Update () {
var targetDir = target.position - transform.position;

// The step size is equal to speed times frame time.
var step = speed * Time.deltaTime;

var newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0);
Debug.DrawRay(transform.position, newDir, Color.red);
// Move our position a step closer to the target.
transform.rotation = Quaternion.LookRotation(newDir);
}```
```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);
}
}
```