当前位置:网站首页>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== | 两个向量是否相等 |
边栏推荐
- Dataworks synchronizes maxcomputer to sqlserver. Chinese characters become garbled. How can I solve it
- 60 divine vs Code plug-ins!!
- Can the polardb MySQL fees for RDS MySQL data migration be transferred?
- How to use AI technology to optimize the independent station customer service system? Listen to the experts!
- Efficient elliptic curve point addition and multiplication in scrypt
- Qt中的数据库使用
- 电机控制park变换公式推导
- 基于ThinkPHP5封装-tronapi-波场接口-源码无加密-可二开--附接口文档-作者详细指导-2022年6月30日08:45:27
- 【一天学awk】数组的使用
- Substrate 源码追新导读: 波卡系波卡权重计算全面更新, Governance 2.0 版本的优化和调整
猜你喜欢

Browser plays RTSP video based on nodejs

Analysis of smart jiangcai login in Jiangxi University of Finance and Economics
![[surprised] the download speed of Xunlei is not as fast as that of the virtual machine](/img/04/b0d23266b70c9ad6990a5203ef8ddf.png)
[surprised] the download speed of Xunlei is not as fast as that of the virtual machine

"Xiaodeng" user personal data management in operation and maintenance

Flinksql customizes udatf to implement topn

【一天学awk】运算符

Google refutes rumors and gives up tensorflow. It's still alive!

Today in history: Microsoft acquires PowerPoint developers; SGI and MIPS merge

ECDSA signature verification in crypt

机器学习笔记 - 自相关和偏自相关简介
随机推荐
Efficient elliptic curve point addition and multiplication in scrypt
JMeter性能测试之相关术语及性能测试通过标准
Apple executives openly "open the connection": Samsung copied the iPhone and only added a large screen
Construction de la plate - forme universelle haisi 3559: obtenir le codage après modification du cadre de données
电机控制Clarke(α/β)等幅值变换推导
Can the polardb MySQL fees for RDS MySQL data migration be transferred?
Wechat launched the picture big bang function; Apple's self-developed 5g chip may have failed; Microsoft solves the bug that causes edge to stop responding | geek headlines
Clipboardjs - development learning summary 1
【MySQL】MySQL的安装与配置
JMeter性能测试工作中遇到的问题及剖析,你遇到了几个?
FlinkSQL自定义UDTF使用的四种方式
Instructions for legend use in SuperMap iclient3d 11i for cesium 3D scene
How to use AI technology to optimize the independent station customer service system? Listen to the experts!
Layout of pyqt5 interface and loading of resource files
Inner join and outer join of MySQL tables
力扣之螺旋矩阵,一起旋转起来(都能看懂)
Substrate 源码追新导读: 质押额度大幅度削减, RocksDB可以完全被Disable
Redis cache problem
ECDSA signature verification in crypt
Introduction to the novelty of substrate source code: comprehensive update of Boca system Boca weight calculation, optimization and adjustment of governance version 2.0