当前位置:网站首页>Common problems of unity (1)
Common problems of unity (1)
2022-04-23 12:52:00 【A little dinosaur without code】
1. Modify object position
You cannot directly modify the of an object position
//transform.position.y = 10f; The wrong way to write
// correct
Vector3 pos = transform.position;
transform.position = new Vector3(pos.x,20f,pos.z);
2. When objects collide with each other, both sides must Collider One of them also has Rigidbody
3. target.position - transform.position What you get is not only direction, but also size
public class Notest : MonoBehaviour
{
public float speed= 5f;
public Transform target;
void Update()
{
// Note that this is not a unit vector target.position - transform.position
transform.position = transform.position + (target.position - transform.position) * speed * Time.deltaTime;
//(target.position - transform.position).normalized normalization
transform.position = transform.position + (target.position - transform.position).normalized * speed * Time.deltaTime;
// improvement : stay update The position is calculated once for each frame in the , The above occurrence vector and number are calculated twice . Add parentheses , Into a vector sum, only one operation is performed It reduces the amount of computation
transform.position = transform.position + (target.position - transform.position).normalized * (speed * Time.deltaTime);
}
}
版权声明
本文为[A little dinosaur without code]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231245553584.html
边栏推荐
- Realize several "Postures" in which a box is horizontally and vertically centered in the parent box
- Fashion cloud learning - input attribute summary
- SSM框架系列——注解开发day2-2
- Introduction to kubernetes
- Image attribute of input: type attribute of fashion cloud learning -h5
- Sort out several uses of network IP agent
- 【微信小程序】z-index失效
- Stm32cubeprogrammer basic instructions
- BUUCTF WEB [BJDCTF2020]The mystery of ip
- leetcode-791. 自定义字符串排序
猜你喜欢
随机推荐
PHP generates JSON to process Chinese
No idle servers? Import OVF image to quickly experience smartx super fusion community version
At instruction of nbiot
4.DRF 权限&访问频率&过滤&排序
【蓝桥杯】4月17日省赛刷题训练(前3道题)
Keyword interpretation and some APIs in RT thread
Zero trust in network information security
Aviation core technology sharing | overview of safety characteristics of acm32 MCU
Bert base Chinese Download (SMART)
Remote access to raspberry pie at home (Part 1)
教你快速开发一个 狼人杀微信小程序(附源码)
uni-app 原生APP-本地打包集成极光推送(JG-JPUSH)详细教程
unity常见的问题(一)
[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
5 free audio material websites, recommended collection
Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward
Get the punch in record of nailing attendance machine
精度、速度完美平衡,最新图像分割SOTA模型重磅发布!!!
NPDP | how can product managers not be excluded by programmers?
BUUCTF WEB [BUUCTF 2018]Online Tool









