c# - Unity 3D - 围绕朝前的圆周移动对象
问题描述
我一直在使用 Unity3D 围绕一个大圆圈的圆周移动播放器,该圆圈面向内朝向中心。
以下代码使用transform.forward工作
// Rotate the forward vector towards the target direction
Vector3 newDirection = Vector3.RotateTowards(transform.forward, targetDirection, singleStep, 0.0f);
然后我通过使用将播放器侧向移动
characterController.Move(horizontalSpeed * transform.right * Time.deltaTime);
我一直坚持如何让玩家绕着圆周移动,但面向前方,玩家的左侧面向圆心。我的代码如下
void Start()
{
characterController = GetComponent<CharacterController>();
}
void Update()
{
// Determine which direction to rotate towards
Vector3 targetDirection = GameObject.Find("Platforms").transform.position - transform.position;
// The step size is equal to speed times frame time.
float singleStep = 1 * Time.deltaTime;
// Rotate the forward vector towards the target direction by one step
Vector3 newDirection = Vector3.RotateTowards(transform.forward, targetDirection, singleStep, 0.0f);
// Draw a ray pointing at our target in
Debug.DrawRay(transform.position, newDirection*50, Color.red);
// Calculate a rotation a step closer to the target and applies rotation to this object
transform.rotation = Quaternion.LookRotation(newDirection);
CheckIfOnGround();
characterController.Move(velocity * Time.deltaTime);
}
解决方案
替换transform.forward
为transform.left
推荐阅读
- foursquare - 从 Foursquare 搜索 api 获取单独的街道号码和街道名称?
- spring-boot - 迁移到最新的 Spring Boot 和 Spring Cloud 后,身份验证服务器 (/oauth/token) 无法正常工作
- xamarin.forms - Container.Resolve 上的棱镜空异常
() - android - 即使应用程序关闭,Ionic 3也会根据本地事件发送通知
- r - R:删除/删除多重共线性变量,基于多重共线性测试输出的输出
- python - 如何忽略某些模型进行迁移?
- c# - 如何基于 @value 将值设置为 JSON
- python - 读取用空格分隔的 int 对象的输入行?
- python - 产品描述在抓取时不返回
- cassandra - 如何在 cassandra 中查找最后一个和第一个条目(日期是分区键的一部分)