当前位置:网站首页>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)
边栏推荐
猜你喜欢

多线程并发之CountDownLatch阻塞等待

(27) Open operation, close operation, morphological gradient, top hat, black hat

重磅披露!上百个重要信息系统被入侵,主机成为重点攻击目标

换掉UUID,NanoID更快更安全!

Machine learning 11 clustering, outlier discrimination

Encryption and decryption of tinyurl in leetcode

String的trim()和substring()详解

Cookies and session keeping technology

(十七)DAC转换实验

Euler function: find the number of numbers less than or equal to N and coprime with n
随机推荐
PETRv2:一个多摄像头图像3D感知的统一框架
Report on research and investment prospects of UHMWPE industry in China (2022 Edition)
两数之和c语言实现[通俗易懂]
线上开通ETF基金账户安全吗?有哪些步骤?
mysql -- explain性能优化
越来越多地使用 SLO 来实现可观测性|DevOps
Vulnhub range hacksudo Thor
GameFramework食用指南
(1) CNN network structure
Pyqt5, draw a histogram on the control
Openlayers customize bubble boxes and navigate to bubble boxes
Vulnhub range hacker_ Kid-v1.0.1
中国锦纶长丝缝纫线发展预测与投资方向研究报告(2022版)
[C supplement] [string] display the schedule of a month by date
How to write good code - Defensive Programming Guide
There is a new breakthrough in quantum field: the duration of quantum state can exceed 5 seconds
[splishsplash] about how to receive / display user parameters, MVC mode and genparam on GUI and JSON
【C語言補充】判斷明天是哪一天(明天的日期)
Encryption and decryption of tinyurl in leetcode
Is it safe to open a stock account by mobile phone? What do you need to bring with you to open an account?