当前位置:网站首页>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== | 两个向量是否相等 |
边栏推荐
- Solve numpy core._ exceptions. Ufunctypeerror: UFUNC 'Add' did not contain a loop with signature matching
- Questionnaire star questionnaire packet capturing analysis
- Substrate 源码追新导读: 5月中旬: Uniques NFT模块和Nomination Pool
- Three ways for flinksql to customize udaf
- ECDSA signature verification in crypt
- The realization of QT the flipping effect of QQ weather forecast window
- kubeedge的核心理念
- 【惊了】迅雷下载速度竟然比不上虚拟机中的下载速度
- Lichuang EDA learning notes 10 common connector component identification and passive buzzer driving circuit
- 腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?
猜你喜欢

黑马笔记---集合(Collection的常用方法与遍历方式)

NoSQL - redis configuration and optimization

黑马笔记---List系列集合与泛型

Reading the table data of Tencent documents in the applet

【OpenGL】OpenGL Examples

Android development interview real question advanced version (with answer analysis)

【一天学awk】数组的使用

Construction de la plate - forme universelle haisi 3559: obtenir le codage après modification du cadre de données

How to select an OLAP database engine?

Questionnaire star questionnaire packet capturing analysis
随机推荐
Building a database model using power designer tools
Flinksql customizes udatf to implement topn
Substrate 源码追新导读: 波卡系波卡权重计算全面更新, Governance 2.0 版本的优化和调整
数据仓库建设之确定主题域
Solve numpy core._ exceptions. Ufunctypeerror: UFUNC 'Add' did not contain a loop with signature matching
Splitting e-commerce systems into micro services
Linux系统Redis的安装
第十三章 信号(三)- 示例演示
Charles打断点修改请求数据&响应数据
药店管理系统
FlinkSQL自定义UDTF使用的四种方式
Why should offline stores do new retail?
Redis - problèmes de cache
How to select an OLAP database engine?
Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年6月29日21:59:34
Sword finger offer 05 Replace spaces: replace each space in the string s with "%20"“
SuperMap iClient3D for WebGL 加载TMS瓦片
JMeter's performance test process and performance test focus
Hisilicon 3559 developing common sense reserves: a complete explanation of related terms
Vision based robot grasping: from object localization, object pose estimation to parallel gripper grasping estimation