public static Vector3 Project (Vector3 vector, Vector3 onNormal);

Descripción

Proyecta un vector sobre otro.

To understand vector projection, imagine that onNormal is resting on a line pointing in its direction. Somewhere along that line will be the nearest point to the tip of vector. The projection is just onNormal rescaled so that it reaches that point on the line.



La función va a retornar un vector cero si onNormal es casi cero.

An example of the usage of projection is a rail-mounted gun that should slide so that it gets as close as possible to a target object. The projection of the target heading along the direction of the rail can be used to move the gun by applying a force to a rigidbody, say.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Slide(Transform target, Vector3 railDirection) { Vector3 heading = target.position - transform.position; Vector3 force = Vector3.Project(heading, railDirection);

GetComponent<Rigidbody>().AddForce(force); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961