当前位置:网站首页>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
边栏推荐
- 21 days learning mongodb notes
- Uni app native app local packaging integrated Aurora push (jg-jpush) detailed tutorial
- 天梯赛赛前练习
- ZigBee CC2530 minimum system and register configuration (1)
- Uni app native app cloud packaging integrated Aurora push (jg-jpush) detailed tutorial
- Zigbee之CC2530最小系统及寄存器配置(1)
- Analysis of InnoDB execution process in MySQL
- Luogu p5540 [balkanoi2011] timeismoney | minimum product spanning tree problem solution
- 8 websites that should be known for product development to enhance work experience
- Buuctf Web [gxyctf2019] no dolls
猜你喜欢
力扣刷题之完全二叉树的节点个数
4.DRF 权限&访问频率&过滤&排序
【蓝桥杯】4月17日省赛刷题训练(前3道题)
【unity笔记】L4Unity中的基础光照
Message queuing overview
教你快速开发一个 狼人杀微信小程序(附源码)
Trier les principales utilisations de l'Agent IP réseau
Customize the shortcut options in El date picker, and dynamically set the disabled date
box-sizing
[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
随机推荐
uni-app 原生APP-云打包集成极光推送(JG-JPUSH)详细教程
21 days learning mongodb notes
XinChaCha Trust SSL Organization Validated
【每日一题】棋盘问题
[vulnhub range] - DC2
梳理網絡IP代理的幾大用途
I changed to a programmer at the age of 31. Now I'm 34. Let me talk about my experience and some feelings
box-sizing
Baserecyclerviewadapterhelper realizes pull-down refresh and pull-up loading
【微信小程序】z-index失效
标签与路径
BUUCTF WEB [BJDCTF2020]The mystery of ip
Luogu p3236 [hnoi2014] picture frame solution
4. DRF permission & access frequency & filtering & sorting
leetcode-791. 自定义字符串排序
云原生KubeSphere部署Mysql
[unity note] basic lighting in l4unity
RT-thread中关键词解释及部分API
在线计算过往日期天数,计算活了多少天
【unity笔记】L4Unity中的基础光照