当前位置:网站首页>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
边栏推荐
- SSL证书退款说明
- Object. The disorder of key value array after keys
- Jiachen chapter Genesis "inner universe" joint Edition
- SPSS之单因素方差分析
- Resolve disagrees about version of symbol device_ create
- 传统企业如何应对数字化转型?这些书给你答案
- Kubernetes 入门教程
- BaseRecyclerViewAdapterHelper 实现下拉刷新和上拉加载
- BUUCTF WEB [BUUCTF 2018]Online Tool
- SSM框架系列——注解开发day2-2
猜你喜欢

解决disagrees about version of symbol device_create

Everything can be expected in the future | one 2022 campus recruitment officially opened

Basic software testing Day2 - Case Execution

SSM framework series - annotation development day2-2

【csnote】ER图

98. Error s.e.errormvcautoconfiguration $staticview reported by freemaker framework: cannot render error page for request

Qt一个进程运行另一个进程
![[unity note] basic lighting in l4unity](/img/38/d88245af2062ed67fb8e61327f3bb9.png)
[unity note] basic lighting in l4unity

传统企业如何应对数字化转型?这些书给你答案

Plato Farm-以柏拉图为目标的农场元宇宙游戏
随机推荐
【vulnhub靶场】-dc2
Hard core parsing promise object (do you know these seven common APIs and seven key questions?)
Qt一个进程运行另一个进程
How does sqlserver insert or update the number of weeks of the day instead of text
PHP generates JSON to process Chinese
Uni app native app local packaging integrated Aurora push (jg-jpush) detailed tutorial
Buuctf Web [bjdctf2020] zjctf, but so
Outsourcing for five years, abandoned
Luogu p5540 [balkanoi2011] timeismoney | minimum product spanning tree problem solution
Fashion cloud learning - input attribute summary
BUUCTF WEB [BJDCTF2020]The mystery of ip
没有空闲服务器?导入 OVF 镜像快速体验 SmartX 超融合社区版
Jiachen chapter Genesis "inner universe" joint Edition
解锁OpenHarmony技术日!年度盛会,即将揭幕!
Qt重绘事件与剪切
BUUCTF WEB [BUUCTF 2018]Online Tool
Metalama简介4.使用Fabric操作项目或命名空间
[daily question] chessboard question
硬核解析Promise对象(这七个必会的常用API和七个关键问题你都了解吗?)
大家帮我看一下这是啥情况,MySQL5.5的。谢了