当前位置:网站首页>Unity脚本的基础语法(5)-向量
Unity脚本的基础语法(5)-向量
2022-06-30 12:18:00 【ht_game】
3D游戏开发中经常需要用到向量的运算,Unity中提供了完整的向量及向量操纵方法,分别为表示二维向量的Vector2类、表示三维向量的Vector3类与表示四维向量的Vector4类。这3种向量用法基本相同。
Vector一般与postion相互联动
或者作为一些API的变量
Vector3类可以在实例化时进行赋值
public class Vector : MonoBehaviour {
public Vector3 position1 = new Vector3();
public Vector3 position2 = new Vector3(1, 2, 2);
void Start()
{
position1.x = 1;
position1.y = 2;
position1.z = 2;
}
void Update()
{
transform.position = position1;
}
}
Vector3类中常量对应的值
| 常量 | 值 |
|---|---|
| Vector3.zero | Vector(0,0,0) |
| Vector3.forward | Vector(0,0,1) |
| Vector3.right | Vector(1,0,0) |
| Vector3.down | Vector(0,-1,0) |
| Vector3.one | Vector(1,1,1) |
| Vector3.up | Vector(0,1,0) |
| Vector3.back | Vector(0,0,-1) |
| Vector3.left | Vector(-1,0,0) |
这些向量常量可以方便使用,不必一直实例化
Vector3类中有很多对向量进行操纵的方法
Vector3类中属性与方法的作用
| 属性/方法 | 作用 |
|---|---|
| magnitude | a向量的长度 |
| normalized | 向量归一化后的结果 |
| sqrMagnitude | 向量的平方长度 |
| Lerp | 两个向量之间的线性插值 |
| Slerp | 在两个向量之间进行球形插值 |
| OrthoNormalize | 使向量规范化并且彼此相互垂直 |
| MoveTowards | 从当前的位置移向目标 |
| RotateTowards | 从当前的向量移向目标 |
| SmoothDamp | 随着时间的推移,逐渐改变一个向量朝向预期的目标 |
| Scale | 两个矢量组件对应相乘 |
| Cross | 两个向量的交叉乘积 |
| Reflect | 沿着法线反射向量 |
| Dot | 两个向量的点乘积 |
| Project | 投影一个向量到另一个向量 |
| Angle | 返回两个 向量的夹角 |
| Distance | 返回两点之间的距离 |
| Min | 返回两个向量中长度较小的向量 |
| Max | 返回两个向量中长度较大的向量 |
| operator+ | 两个向量相加 |
| operator+ | 两个向量相减 |
| operator* | 两个向量相乘 |
| operator/ | 两个向量相除 |
| operator== | 两个向量是否相等 |
边栏推荐
- 基于ThinkPHP5封装tronapi-波场接口-PHP版本--附接口文档-20220627
- Three ways for flinksql to customize udaf
- How to select an OLAP database engine?
- 【OpenGL】OpenGL Examples
- Lichuang EDA learning notes 10 common connector component identification and passive buzzer driving circuit
- Qt中的事件处理
- Analysis of smart jiangcai login in Jiangxi University of Finance and Economics
- Commands for redis basic operations
- Charles break point modify request data & response data
- [MySQL] MySQL installation and configuration
猜你喜欢

江西财经大学智慧江财登录分析
![[qnx hypervisor 2.2 user manual]6.2.3 communication between guest and external](/img/ca/9065325ce8882d95fb24c82fb62abc.png)
[qnx hypervisor 2.2 user manual]6.2.3 communication between guest and external
![[QNX Hypervisor 2.2用户手册]6.2.3 Guest与外部之间通信](/img/ca/9065325ce8882d95fb24c82fb62abc.png)
[QNX Hypervisor 2.2用户手册]6.2.3 Guest与外部之间通信

Building a database model using power designer tools

SuperMap 3D SDKs_ Unity plug-in development - connect data services for SQL queries

Redis cache problem

ECDSA signature verification in crypt

SuperMap iClient3D 11i for Cesium三维场景中图例使用说明

Four ways for flinksql to customize udtf

QT MSVC installation and commissioning
随机推荐
SQLSERVER 查询编码是 936 简体中文GBK,那我是写936 还是写GBK?
Hisilicon 3559 universal platform construction: introduction to YUV format
Hisilicon 3559 developing common sense reserves: a complete explanation of related terms
Qt读写Excel--QXlsx工作表显示/隐藏状态设置4
【惊了】迅雷下载速度竟然比不上虚拟机中的下载速度
Hisilicon 3559 sample parsing: Venc
MATLAB小技巧(22)矩阵分析--逐步回归
Spatiotemporal prediction 2-gcn_ LSTM
时空预测2-GCN_LSTM
Sarsa notes
FlinkSQL自定义UDATF实现TopN
两批次纯牛奶不合格?麦趣尔回应:正对产品大批量排查抽检
ECDSA signature verification in crypt
Redis - problèmes de cache
Solve numpy core._ exceptions. Ufunctypeerror: UFUNC 'Add' did not contain a loop with signature matching
7 lightweight and easy-to-use tools to relieve pressure and improve efficiency for developers, and help enterprises' agile cloud launch | wonderful review of techo day
Flink SQL console, group not recognized_ Concat function?
Sqlserver query code is 936 simplified Chinese GBK. Should I write 936 or GBK?
JMeter's performance test process and performance test focus
Double dqn notes