当前位置:网站首页>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)
边栏推荐
- China metallocene polyethylene (MPE) Industry Research Report (2022 Edition)
- Development cost of smart factory management system software platform
- Object. fromEntries()
- Report on Market Research and investment prospects of ammonium dihydrogen phosphate industry in China (2022 Edition)
- PETRv2:一个多摄像头图像3D感知的统一框架
- 整形数组合并【JS】
- Intel's open source deep learning tool library openvino will increase cooperation with local software and hardware parties and continue to open
- Vulnhub range hacker_ Kid-v1.0.1
- Develop those things: easycvr cluster device management page function display optimization
- Enter wechat applet
猜你喜欢

Iommu/smmuv3 code analysis (10) page table operation

Why should you consider using prism

How to write good code - Defensive Programming Guide

In aks, use secret in CSI driver mount key vault

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

Euler function: find the number of numbers less than or equal to N and coprime with n

National Security Agency (NSA) "sour Fox" vulnerability attack weapon platform technical analysis report

Cookies and session keeping technology

整形数组合并【JS】

Intelligent operation and maintenance practice: banking business process and single transaction tracking
随机推荐
官宣!香港科技大学(广州)获批!
Leetcode records - sort -215, 347, 451, 75
Depth first traversal and breadth first traversal [easy to understand]
Detailed explanation of string's trim() and substring()
换掉UUID,NanoID更快更安全!
Transition technology from IPv4 to IPv6
如何写出好代码 — 防御式编程指南
Kia recalls some K3 new energy with potential safety hazards
英特尔开源深度学习工具库 OpenVINO,将加大与本土软硬件方合作,持续开放
【C語言補充】判斷明天是哪一天(明天的日期)
Soft test software designer full truth simulation question (including answer analysis)
In depth Research Report on China's disposable sanitary products production equipment industry (2022 Edition)
DRF --- response rewrite
MySQL learning summary
Encryption and decryption of tinyurl in leetcode
China PBAT resin Market Forecast and Strategic Research Report (2022 Edition)
Pytest learning notes (13) -allure of allure Description () and @allure title()
字节跳动数据平台技术揭秘:基于 ClickHouse 的复杂查询实现与优化
In aks, use secret in CSI driver mount key vault
Maizeer: the two batches of products reported by the media have been taken off the shelves and sealed, and consumer appeals are accepted