实现手游中通过摇杆控制角色移动的方式
主要代码:
void Move(){
Vector2 offset = new Vector2(ETCInput.GetAxis("Horizontal"), ETCInput.GetAxis("Vertical")); //摇杆输入
if (offset.magnitude == 0) //当摇杆没有偏移时角色朝向不变
transform.forward = transform.forward;
else {
cameraForward = mainCamera.transform.right * offset.x+ mainCamera.transform.forward* offset.y;
cameraForward = new Vector3(-cameraForward.x, 0, -cameraForward.z);
transform.forward = cameraForward;
}
if (offset.magnitude > 0.1) //最小移动距离
player.SimpleMove( cameraForward* moveSpeed);
}
代码是附加于需要控制的角色上