当前位置:网站首页>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

边栏推荐
- How to configure DDR3 of dm8148
- Airflow2.1.1 ultra detailed installation document
- Update pip to the latest version
- ROS notes (08) - definition and use of service data
- Devops foundation chapter Jenkins deployment (II)
- SQL analysis (query interception analysis for SQL optimization)
- sql主從複制搭建
- Study notes 22/1/17
- GPIO configuration of SOC
- Section 8: DMA of zynq
猜你喜欢

Online WPS tool

sql主从复制搭建

MySQL installation and environment variable configuration

微内核Zephyr获众多厂家支持!

Ambari (V) ---ambari integrated Azkaban (valid for personal test)

城联优品向英德捐赠抗洪救灾爱心物资

Jacobian matrix J commonly used in slam

Jenkins' common build trigger and hook services (V)

B_ QuRT_ User_ Guide(28)

2022巴黎时装周儿童单元6.19武汉站圆满落幕
随机推荐
Porting ucosiii to stm32f429
Trigonometric transformation formula
券商注册开户靠谱吗?安全吗?
Image translation /transformer:ittr: unpaired image to image translation with transformers
Hj21 simple password
你了解TCP协议吗(一)?
Study notes 22/1/18
Idea package together, using compact middle packages to solve &
三角变换公式
Kubernetes theoretical basis
cuda和cudnn和tensorrt的理解
22/02/14 study notes
Co process, asyncio, asynchronous programming
Is it reliable for the top ten securities companies to register and open accounts? Is it safe?
探讨gis三维系统在矿山行业中的应用
SQL Master slave Replication Build
2022第六季完美童模 佛山赛区 初赛圆满落幕
Flex layout
asp. Net datalist to display product information and pictures
B_QuRT_User_Guide(28)