当前位置:网站首页>Unity gets the coordinate point in front of the current object at a certain angle and distance
Unity gets the coordinate point in front of the current object at a certain angle and distance
2022-06-28 08:09:00 【Star_ MengMeng】
1. Sometimes the scene needs to have fixed objects or Canvas Generated directly in front of the character (VR It is more commonly used in English )


The code is simple :
Vector3 targetPos = rig.transform.forward * 2f + rig.transform.position;
wui.transform.position = targetPos;
wui.transform.LookAt(rig.transform);
You can also add angles :
public Vector3 GetPosition(Quaternion rotation, Vector3 position, float distance)
{
Vector3 direction = rotation * Vector3.forward;
return position + (direction * distance);
}
If the object is Canvas(world Space Pattern ), Notice the pros and cons of the canvas , It can be modified by scale Change the flip of the canvas : Such as ,gui.transform.localScale=Vector3(-1,1,1)
2. For example, I want to get the angle value of a point right in front of me ( Nodes at the same level are required , Different levels need to convert coordinates first )
public class Example : MonoBehaviour
{
public float angleBetween = 0.0f;
public Transform target;
void Update()
{
Vector3 targetDir = target.position - transform.position;
angleBetween = Vector3.Angle(transform.forward, targetDir);
}
}
Vector3 Subtract to get the direction vector , And then transform.forward Take angle .
3. Pay attention to these two common forward The difference between

边栏推荐
- [JS] - [throttling and anti shake function]
- 【学习笔记】搜索
- asp. Net datalist when there are multiple data displays
- [JS] - [DFS, BFS application] - learning notes
- SQL Master slave Replication Build
- Localization SoC development plan
- Study notes 22/1/19 and 22/1/20
- MySQL installation and environment variable configuration
- Flex layout
- sql主从复制搭建
猜你喜欢

Do you know TCP protocol (2)?

软件测试与质量期末复习

Ambari (VII) --- ambari integrated hue4.2 document (valid for personal test)

22/02/14 study notes

【js】-【DFS、BFS应用】-学习笔记

Eslint 语法监测关闭

Upgrade HDP spark to spark 2.4.8 without upgrading ambari

安装nrm后,使用nrm命令报错internal/validators.js:124 throw new ERR_INVALID_ARG_TYPE(name, ‘string‘, value)

How to configure DDR3 of dm8148

探讨gis三维系统在矿山行业中的应用
随机推荐
Redis uses sentinel master-slave switching. What should the program do?
关于如何在placeholder中使用字体图标
LeetCode之三步问题
B_ QuRT_ User_ Guide(30)
Es data export CSV file
B_QuRT_User_Guide(29)
安装nrm后,使用nrm命令报错internal/validators.js:124 throw new ERR_INVALID_ARG_TYPE(name, ‘string‘, value)
设置网页的标题部分的图标
Section 8: DMA of zynq
HJ string sort
【学习笔记】搜索
How to insert a single quotation mark into a table as a data type in Oracle pl/sql
Online WPS tool
ROS notes (09) - query and setting of parameters
Uvcgan: unt vision transformer cycle-consistent Gan for unpropared image-to-image translation
How redis solves cache avalanche, breakdown and penetration problems
B_ QuRT_ User_ Guide(28)
同花顺注册开户靠谱吗?安全吗?
HJ base conversion
Cloud native: cloud computing technology is upgraded again to open an era of comprehensive cloud development