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

パラメーター

current The vector being managed.
target The vector.
maxRadiansDelta The distance between the two vectors in radians.
maxMagnitudeDelta The length of the radian.

戻り値

Vector3 The location that RotateTowards generates.

説明

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

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

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { // The target marker. Transform target;

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

void Update() { Vector3 targetDir = target.position - transform.position;

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

Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0f); Debug.DrawRay(transform.position, newDir, Color.red);

// Move our position a step closer to the target. transform.rotation = Quaternion.LookRotation(newDir); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961