当前位置:网站首页>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
边栏推荐
- SSL证书退款说明
- NPDP | how can product managers not be excluded by programmers?
- Object. The disorder of key value array after keys
- BUUCTF WEB [BJDCTF2020]The mystery of ip
- Labels and paths
- php生成json处理中文
- Trier les principales utilisations de l'Agent IP réseau
- 进程虚拟地址空间区域划分
- [daily question] chessboard question
- One way ANOVA of SPSS
猜你喜欢

产品开发都应该知道的8个网站,增强工作体验

梳理网络IP代理的几大用途

CGC: contractual graph clustering for community detection and tracking

Introduction to metalama 4 Use fabric to manipulate items or namespaces

Use source insight to view and edit source code

Image attribute of input: type attribute of fashion cloud learning -h5

0基础可以考CPDA数据分析师证书吗

22. 括号生成

XinChaCha Trust SSL Organization Validated

One way ANOVA of SPSS
随机推荐
22. 括号生成
Uni app native app cloud packaging integrated Aurora push (jg-jpush) detailed tutorial
Aviation core technology sharing | overview of safety characteristics of acm32 MCU
leetcode:437. 路径总和 III【dfs 选还是不选?】
[vulnhub range] - DC2
基于卷积神经网络的遥感影像分类识别系统
How does sqlserver insert or update the number of weeks of the day instead of text
php生成json处理中文
Trier les principales utilisations de l'Agent IP réseau
Packet capturing and sorting -- TCP protocol [8]
实现一个盒子在父盒子中水平垂直居中的几种“姿势”
进程虚拟地址空间区域划分
No idle servers? Import OVF image to quickly experience smartx super fusion community version
产品开发都应该知道的8个网站,增强工作体验
解锁OpenHarmony技术日!年度盛会,即将揭幕!
Hard core parsing promise object (do you know these seven common APIs and seven key questions?)
SynchronousQueue 源码解析
BUUCTF WEB [BJDCTF2020]The mystery of ip
世界读书日:我想推荐这几本书
Use source insight to view and edit source code