找回密码
 立即注册
查看: 170|回复: 0

Unity LookAt和LookRotation的使用

[复制链接]
发表于 2022-12-1 16:50 | 显示全部楼层 |阅读模式
始终看向某一个物体

transform.LookAt(Obj.transform);Debug.DrawLine(transform.position, Obj.transform.position, Color.blue);保持和同一个物体,同一个朝向

   transform.rotation = Quaternion.LookRotation(Obj.transform.forward);   Debug.DrawRay(transform.position, Obj.transform.forward, Color.red);但是当Obj发生上下移动(不在同一个水平面)时,就能看到差别了,物体始终朝向Obj,但是物体只改变水平方向的转向

Vector3 dir = Obj.transform.position - transform.position;        dir = new Vector3(dir.x, 0, dir.z);        transform.rotation = Quaternion.LookRotation(dir);        Debug.DrawRay(transform.position, dir, Color.green);
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-6-16 18:38 , Processed in 0.096510 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表