- Home /
Question is off-topic or not relevant
Cant optimize rotation axes to android joystick
I'm making a game about knight fighting. And now I'm making my spear controller. So I tried to do delayed motion or motion by impulse for my game. All I did is simply transform rotation by standard joystick from asset store. But that's not what I need. Finally, I found this script. This is exactly what I wanted but not works with my joystick. Problem in rotation axes, I cant optimize these axes for joystick. 6 hours of search. More than 5 tutorials revised. Nothing helped. Ok its my first script
using UnityEngine;
using CnControls;
public class RotatorSc : MonoBehaviour
{
public float minX;
public float maxX;
public float minY = -45.0f;
public float maxY = 45.0f;
public float sensX = 100.0f;
public float sensY = 100.0f;
float rotationY = 0.0f;
float rotationX = 0.0f;
void Update()
{
if (Input.GetMouseButton(0))
{
rotationX += CnInputManager.GetAxis("Horizontal") * sensX * Time.deltaTime;
rotationY -= CnInputManager.GetAxis("Mouse Y") * sensY * Time.deltaTime;
rotationY = Mathf.Clamp(rotationY, minY, maxY);
rotationX = Mathf.Clamp(rotationX, minX, maxX);
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
}
}
And second script (which I need)
{
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;
public float smooth = 2;
float smoothXAxis;
float smoothYAxis;
public float minimumX = -45F;
public float maximumX = 45F;
public float minimumY = -45F;
public float maximumY = 45F;
float rotationY = 0F;
void Update()
{
smoothXAxis = Mathf.Lerp(smoothXAxis, Input.GetAxis("Mouse X"), Time.deltaTime * smooth);
smoothYAxis = Mathf.Lerp(smoothYAxis, Input.GetAxis("Mouse Y"), Time.deltaTime * smooth);
if (axes == RotationAxes.MouseXAndY)
{
float rotationX = transform.localEulerAngles.y + smoothXAxis * sensitivityX;
rotationY += smoothYAxis * sensitivityY;
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
else if (axes == RotationAxes.MouseX)
{
transform.Rotate(0, smoothXAxis * sensitivityX, 0);
}
else
{
rotationY += smoothYAxis * sensitivityY;
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
}
}
}
Ill be grateful for any help
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
move the object where camera look 0 Answers
Distribute terrain in zones 3 Answers
Joystick move Left Right and down, plus rotation. 0 Answers
Rotate the weapon sprite with a joystick 0 Answers