wasd+鼠标控制
Vector3 rotAngle = Vector3.zero;
CharacterController controller;
Vector3 direction = Vector3.zero;
public Transform cam;
float rotY;
float x;
float y;
public Transform target;
private void Awake()
{
// controller = GetComponent<CharacterController>();
}
private void Update()
{
if (Input.GetMouseButton(0))
{
rotY = Input.GetAxis("Mouse X");
rotAngle.y += rotY;
transform.rotation = Quaternion.Euler(rotAngle);
}
x = Input.GetAxis("Horizontal");
y = Input.GetAxis("Vertical");
if (x != 0 || y != 0)
{
direction = transform.forward * y + transform.right * x;
controller.SimpleMove(direction);
}
}
EasyTouch摇杆控制
private void Start()
{
joystick = GetComponent<ETCJoystick>();
joystick.onMove.AddListener(JoystickMove);
rotMsg = new MsgVector2((ushort)CharacterEvent.ChangeRot, Vector2.zero);
}
private void JoystickMove(Vector2 v)
{
float angle = Mathf.Atan2(v.x, v.y)*Mathf.Rad2Deg;
rot.y = angle;
transform.rotation = Quaternion.Euler(rot);
float speed = Mathf.Sqrt(v.x * v.x + v.y * v.y);
// direction.y = 0;
direction.x = v.x;
direction.z = v.y;
controller.SimpleMove(direction*speed);
// controller.SimpleMove(transform.forward * speed);
}