public class player22 : MonoBehaviour {
public float speed=10.0F;
void Update()
{
CharacterController controller = GetComponent<CharacterController> ();
transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);
Vector3 forward = transform.TransformDirection(Vector3.forward);
float curSpeed = speed * Input.GetAxis("Vertical");
controller.SimpleMove(forward * curSpeed);
}
这是前后移动,在通过旋转 转换方向 siki老师有没有左右移动的方法 --之前视频代码好像过时了
你想左右移动的话,可以吧作用控制旋转的修改一下
CharacterController controller = GetComponent<CharacterController> ();
Vector3 forward = transform.TransformDirection(Vector3.forward);
Vector3 right= transform.TransformDirection(Vector3.right);
float curSpeed = speed * Input.GetAxis("Vertical");
float curSpeed2 = speed * Input.GetAxis("Horizontal");
controller.SimpleMove(forward * curSpeed+right*curSpeed2);