我一直在使用 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);
}
答案 0 :(得分:0)
将 transform.forward
替换为 transform.left