- Home /
Question by
metobayrak · Jun 21, 2015 at 11:18 AM ·
playerrotatejoystick
Rotate the Player With Joystick
I want to rotate my player with an joystick. Actually, it works. But, when i rotate the joystick, Player was whirling around. İt didn't stopped. I want, it just look. Sorry for my bad english.
Joystick script:
public void OnDrag(PointerEventData data) {
Vector3 newPos = Vector3.zero;
if (useX) {
int delta = (int) (data.position.x - startPos.x);
delta = Mathf.Clamp(delta, - MovementRange, MovementRange);
newPos.x = delta;
}
if (useY)
{
int delta = (int)(data.position.y - startPos.y);
delta = Mathf.Clamp(delta, -MovementRange, MovementRange);
newPos.y = delta;
}
transform.position = new Vector3(startPos.x + newPos.x , startPos.y + newPos.y , startPos.z + newPos.z);
UpdateVirtualAxes (transform.position);
}
MouseLook script:
void Update ()
{
if (axes == RotationAxes.MouseXAndY)
{
float rotationX = transform.localEulerAngles.y + CrossPlatformInputManager.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
else if (axes == RotationAxes.MouseX)
{
transform.Rotate(0, CrossPlatformInputManager.GetAxis("Mouse X") * sensitivityX, 0);
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
}
}
Comment
Your answer
Follow this Question
Related Questions
Camera rotation around player while following. 6 Answers
2D rotation around hinge joint with joystick input 0 Answers
Rotate whole scene by 90 degrees 1 Answer
I need help with prefabs 1 Answer