【发布时间】:2018-05-10 13:08:32
【问题描述】:
我正在制作一个游戏,它包含行星引力,我如何才能让玩家看到它正在移动的方向,如果我可以将它插入到我的移动代码中会很有帮助
using UnityEngine;
public class PlayerMovementScript : MonoBehaviour {
public float moveSpeed;
private Vector3 moveDirection;
void Update()
{
moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
}
void FixedUpdate()
{
GetComponent<Rigidbody>().MovePosition(GetComponent<Rigidbody>().position + transform.TransformDirection(moveDirection) * moveSpeed * Time.deltaTime);
}
}
【问题讨论】:
-
您是否尝试过使用LookAt() 方法?您可以将其传递给您的
(moveDirection + gameObject.transform.position),它应该可以工作。 -
使用
Input.GetAxisRaw("Horizontal")或←→来控制方向和Input.GetAxisRaw("Vertical")或↑↓来控制移动是有意义的。 -
@Paul-Jan 该链接显示“没有刚体”。 OP 正在使用刚体。
-
@Programmer 不管标题细节如何,接受的答案还提到了如何使用 RigidBody 执行此操作。但你是对的,删除了关闭建议。