Rotate a character with joystick
Hi, i have a question.
I make Joystick.
The Target is Character.
Well... The moving is well.
But, rotate is not good.
When i use touched position like this :
if (Input.GetMouseButtonDown(0)) { if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) { touchedPos = hit.point; dir = Quaternion.LookRotation( (touchedPos - transform.position).normalized); dir.x = 0; dir.z = 0; } } transform.rotation = Quaternion.Slerp(transform.rotation, dir, turnSpeed * Time.deltaTime); }
This code is nice moving.
But, now I doesn't use Input.GetMouseButtonDown.
Only use Joystick for device. like this :
Vector3 touchPos = UICamera.currentCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
Vector3 dir = (touchPos - oriPosition).normalized;
float length = Vector3.Distance(oriPosition, touchPos);
if (length > stickRadius)
transform.position = oriPosition + (dir * stickRadius);
else
transform.position = touchPos;
/// direction
Target.MoveCharacter( new Vector3(dir.x, 0, dir.y) );
/// ratate
Target.GetComponent<Turn>().SetRotation( ???? );
Q : How to ratate a character with joystick in 3d Model ? // The rotate axis is Y.