当前位置:网站首页>unity常见的问题(一)
unity常见的问题(一)
2022-04-23 12:46:00 【一个不会码代码的小恐龙】
1.修改物体位置
无法直接修改物体的position
//transform.position.y = 10f; 错误的写法
//修正
Vector3 pos = transform.position;
transform.position = new Vector3(pos.x,20f,pos.z);
2.物体相互碰撞两方必须都要Collider 其中一方还要有 Rigidbody
3. target.position - transform.position 得到的不仅有方向还有大小
public class Notest : MonoBehaviour
{
public float speed= 5f;
public Transform target;
void Update()
{
//注意这不是单位向量 target.position - transform.position
transform.position = transform.position + (target.position - transform.position) * speed * Time.deltaTime;
//(target.position - transform.position).normalized 归一化处理
transform.position = transform.position + (target.position - transform.position).normalized * speed * Time.deltaTime;
//改进:在update中每一帧都要计算一次位置,上述出现向量和数进行了两次运算。加上小括号,变为向量和数只进行了一次运算 减少了运算量
transform.position = transform.position + (target.position - transform.position).normalized * (speed * Time.deltaTime);
}
}
版权声明
本文为[一个不会码代码的小恐龙]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_52021450/article/details/124348147
边栏推荐
- SSM框架系列——Junit单元测试优化day2-3
- 标签与路径
- 4. DRF permission & access frequency & filtering & sorting
- Lesson 26 static member functions of classes
- STM32CubeProgrammer基础使用说明
- Plato Farm-以柏拉图为目标的农场元宇宙游戏
- leetcode-791. 自定义字符串排序
- STM32 project transplantation: transplantation between chip projects of different models: Ze to C8
- Object. The disorder of key value array after keys
- SSM framework series - annotation development day2-2
猜你喜欢
Deploying MySQL in cloud native kubesphere
NPDP | how can product managers not be excluded by programmers?
Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward
云原生KubeSphere部署Mysql
QT one process runs another
Introduction to metalama 4 Use fabric to manipulate items or namespaces
Zigbee之CC2530最小系统及寄存器配置(1)
Unable to create servlet under SRC subfile of idea
网络信息安全之零信任
SSL证书退款说明
随机推荐
QT one process runs another
Introduction to metalama 4 Use fabric to manipulate items or namespaces
At instruction of nbiot
Lesson 26 static member functions of classes
98. Error s.e.errormvcautoconfiguration $staticview reported by freemaker framework: cannot render error page for request
Realize several "Postures" in which a box is horizontally and vertically centered in the parent box
Message queuing overview
C, calculation code of parameter points of two-dimensional Bezier curve
4.DRF 权限&访问频率&过滤&排序
BUUCTF WEB [BUUCTF 2018]Online Tool
Object. The disorder of key value array after keys
Idea的src子文件下无法创建servlet
How does sqlserver insert or update the number of weeks of the day instead of text
Jiachen chapter Genesis "inner universe" joint Edition
【微信小程序】z-index失效
洛谷P3236 [HNOI2014]画框 题解
Qt重绘事件与剪切
BUUCTF WEB [BJDCTF2020]The mystery of ip
Markdown语法学习
Deploying MySQL in cloud native kubesphere