Мои Уведомления
Привет, !
Мой Аккаунт Мои Финансы Мои Подписки Мои Настройки Выход
Руководство API скрипты

Vector3.ClampMagnitude

Объявление

public static Vector3 ClampMagnitude(Vector3 vector, float maxLength);

Описание

Возвращает копию vector с величиной, ограниченной maxLength.

using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { // Перемещайте объект с помощью клавиш со стрелками, но ограничивайте его // до заданного радиуса вокруг центральной точки. public Vector3 centerPt; public float radius; void Update() { // Get the new position for the object. Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); Vector3 newPos = transform.position + movement; // Calculate the distance of the new position from the center point. Keep the direction // the same but clamp the length to the specified radius. Vector3 offset = newPos - centerPt; transform.position = centerPt + Vector3.ClampMagnitude(offset, radius); } }
Вы можете отблагодарить автора, за перевод документации на русский язык. ₽ Спасибо
API скрипты 2021.3