当前位置:网站首页>transform. Forward and vector3 Differences in the use of forward
transform. Forward and vector3 Differences in the use of forward
2022-07-01 17:35:00 【ZEKEGU1997】
unity There are several direction vectors that can be used directly , Namely transform.forward,transform.up,transform.right and Vector3.forward,Vector3.up,Vector3.right.
In terms of numbers ,transform.forward,transform.up,transform.right Is the direction vector of the three axes in the game object's own coordinate system , and Vector3.forward,Vector3.up,Vector3.right Are the three axes of world coordinates .

But when transform.translate and transform.rotate When the function uses these vectors, you should pay attention to .
For example, we want an object to always move forward along its own coordinate system , Take it for granted that it will be written like this
void Update()
{
if(Input.GetKey(KeyCode.W))
transform.Translate(transform.forward * Time.deltaTime * 1.0f);
}But in this way, if the object coordinate system is inconsistent with the world coordinate , Moving in a strange direction , It is not along the axis of world coordinates or its own coordinates , The black tip in the figure below is the actual moving direction .

How did this strange direction come from

Pictured above , Set the blue arrow in its coordinate system as x1, The black arrow is y1, Rotate the object coordinate system so that it coincides with the world coordinates , that y1 It also rotates together to get the black arrow on the left y2, and y2 And x1 parallel , That is, the direction vector is the same , Push this process backward to get y1 Is the actual direction of movement . So clearly , This complex process and its results are not what we want .
actually ,translate and rotate These two functions can input coordinate system parameters , If it is not entered, the default value is space.self. If you want to move forward along your own coordinates, there are two ways to write , Rotating along its own coordinate system is the same
transform.translate(vector3.forward,Space.self)
transform.translate(transform.forward,Space.world)
边栏推荐
- 如何使用 etcd 实现分布式 /etc 目录
- 中国超高分子量聚乙烯产业调研与投资前景报告(2022版)
- SQL injection vulnerability (MySQL and MSSQL features)
- [mathematical modeling] [matlab] implementation of two-dimensional rectangular packing code
- Sword finger offer II 105 Maximum area of the island
- ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享
- Is it safe to open an ETF account online? What are the steps?
- 走进微信小程序
- 【Try to Hack】vulnhub DC4
- redis -- 数据类型及操作
猜你喜欢

【C补充】【字符串】按日期排序显示一个月的日程

字节跳动数据平台技术揭秘:基于 ClickHouse 的复杂查询实现与优化

(十七)DAC转换实验

多线程使用不当导致的 OOM

如何使用 etcd 实现分布式 /etc 目录

英特尔开源深度学习工具库 OpenVINO,将加大与本土软硬件方合作,持续开放

Countdownlatch blocking wait for multithreading concurrency

(17) DAC conversion experiment

vulnhub靶场-hacksudo - Thor

Sword finger offer 20 String representing numeric value
随机推荐
New patent applications and transfers
Yyds dry inventory MySQL RC transaction isolation level implementation
6月刊 | AntDB数据库参与编写《数据库发展研究报告》 亮相信创产业榜单
Hidden Markov model (HMM): model parameter estimation
Good looking UI mall source code has been scanned, no back door, no encryption
Soft test software designer full truth simulation question (including answer analysis)
China BMS battery management system Market Research Report (2022 Edition)
[C language supplement] judge which day tomorrow is (tomorrow's date)
如何使用 etcd 实现分布式 /etc 目录
China PBAT resin Market Forecast and Strategic Research Report (2022 Edition)
中国茂金属聚乙烯(mPE)行业研究报告(2022版)
(17) DAC conversion experiment
期货先锋这个软件正规吗安全吗?选择哪家期货公司更安全?
Depth first traversal and breadth first traversal [easy to understand]
Radhat builds intranet Yum source server
中国一次性卫生用品生产设备行业深度调研报告(2022版)
(16) ADC conversion experiment
Leetcode records - sort -215, 347, 451, 75
换掉UUID,NanoID更快更安全!
(十六)ADC转换实验