C
C#13mo ago
jupiter_butts

❔ Unity C#, this is regarding the rotation problem using new input system

Script A : this is for input manager
public class ManagerInput: MonoBehaviour
{
Vector3 moveInput;
Vector2 rotateInput;
public float rotationAxisX;
public float rotationAxisY;
public float xAxis, zAxis;

private void OnEnable()
{
InputSystem.EnableDevice(Gamepad.current);
}

private void OnDisable()
{
InputSystem.DisableDevice(Gamepad.current);
}
private void Update()
{
RotateInput();
}

void RotateInput()
{
rotationAxisX = rotateInput.x;
}
private void OnMove(InputValue value) => moveInput = value.Get<Vector3>();
private void OnRotate(InputValue value) => rotateInput = value.Get<Vector2>();

}
public class ManagerInput: MonoBehaviour
{
Vector3 moveInput;
Vector2 rotateInput;
public float rotationAxisX;
public float rotationAxisY;
public float xAxis, zAxis;

private void OnEnable()
{
InputSystem.EnableDevice(Gamepad.current);
}

private void OnDisable()
{
InputSystem.DisableDevice(Gamepad.current);
}
private void Update()
{
RotateInput();
}

void RotateInput()
{
rotationAxisX = rotateInput.x;
}
private void OnMove(InputValue value) => moveInput = value.Get<Vector3>();
private void OnRotate(InputValue value) => rotateInput = value.Get<Vector2>();

}
Script B: This is for the player to execute the movement/rotation
public class CharacterMove: MonoBehaviour
{
Rigidbody rb;

P_Input p_input;

[SerializeField] float speed;
[SerializeField] float rotationSpeedForPad = 5f;

private void Awake()
{
rb = GetComponent<Rigidbody>();
p_input = GetComponent<P_Input>();
}

void FixedUpdate()
{

PadRotate();
}

void PadRotate()
{
float rotation = p_input.rotationAxisX * rotationSpeedForPad;
Quaternion deltaRotation = Quaternion.Euler(0f, rotation, 0f);
rb.MoveRotation(rb.rotation * deltaRotation);
}
}
public class CharacterMove: MonoBehaviour
{
Rigidbody rb;

P_Input p_input;

[SerializeField] float speed;
[SerializeField] float rotationSpeedForPad = 5f;

private void Awake()
{
rb = GetComponent<Rigidbody>();
p_input = GetComponent<P_Input>();
}

void FixedUpdate()
{

PadRotate();
}

void PadRotate()
{
float rotation = p_input.rotationAxisX * rotationSpeedForPad;
Quaternion deltaRotation = Quaternion.Euler(0f, rotation, 0f);
rb.MoveRotation(rb.rotation * deltaRotation);
}
}
Hi with this input, how do I rotate according to how my right analog stick being pushed? right now, this all works, but the character rotation works weird because it only works when i push left, right, and diagonal, which will cause some weird rotation (i know it made it that way because this is the only code i know on how to incorporate rotation). Any suggestion pls?
2 Replies
FusedQyou
FusedQyou13mo ago
You're better off asking this in #input-system in the discord server
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.