当前位置:网站首页>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)
边栏推荐
- Soft test network engineer full truth simulation question (including answer and analysis)
- Thinkphp6 - CMS multi wechat management system source code
- PETRv2:一个多摄像头图像3D感知的统一框架
- ACL 2022 | decomposed meta learning small sample named entity recognition
- ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享
- Unity3d extended toolbar
- Report on Market Research and investment prospects of ammonium dihydrogen phosphate industry in China (2022 Edition)
- (17) DAC conversion experiment
- SLO is increasingly used to achieve observability | Devops
- Roewe rx5's "a little more" product strategy
猜你喜欢
Computed property “xxx“ was assigned to but it has no setter.
剑指 Offer 20. 表示数值的字符串
【牛客网刷题系列 之 Verilog快速入门】~ 优先编码器电路①
The difference and relationship between iteratible objects, iterators and generators
String的trim()和substring()详解
Oom caused by improper use of multithreading
ShenYu 网关开发:在本地启用运行
Leetcode records - sort -215, 347, 451, 75
SQL injection vulnerability (MySQL and MSSQL features)
Why should you consider using prism
随机推荐
The amazing open source animation library is not only awesome, but also small
ACL 2022 | decomposed meta learning small sample named entity recognition
中国乙腈市场预测与战略咨询研究报告(2022版)
New patent applications and transfers
深度优先遍历和广度优先遍历[通俗易懂]
线上开通ETF基金账户安全吗?有哪些步骤?
Pyqt5, draw a histogram on the control
PETRv2:一个多摄像头图像3D感知的统一框架
Replace UUID, nanoid is faster and safer!
SQL注入漏洞(Mysql与MSSQL特性)
Unity3d extended toolbar
Develop those things: easycvr cluster device management page function display optimization
Intelligent operation and maintenance practice: banking business process and single transaction tracking
走进微信小程序
C language implementation of sum of two numbers [easy to understand]
麦趣尔:媒体报道所涉两批次产品已下架封存,受理消费者诉求
(12) About time-consuming printing
[Verilog quick start of Niuke network question brushing series] ~ priority encoder circuit ①
unity3d扩展工具栏
Hidden Markov model (HMM): model parameter estimation