I’m trying to make joystick controls that have two fixed speeds, walk and run, with no sensitivity. The problem I’m encountering is that without directly using the axis input, the player’s rotation becomes stiff as though using WASD, which is exactly what I don’t want. My current workaround is to determine which input is greater and set it to a fixed speed while the other is input sensitive. This creates the illusion of fixed speed, but it still doesn’t do what I want. (The stiff movement still occurs when walking.) Here’s the code I have right now:
totInput = Mathf.Sqrt(hInput * hInput + fInput * fInput);
// Determine Speed
if (totInput > 0.7f)
speed = speedFast;
else
speed = speedSlow;
// Horizontal Movement
if (hInput != 0)
{
if (Mathf.Abs(fInput) >= Mathf.Abs(hInput))
transform.Translate(Vector3.right * speed * hInput * Time.deltaTime);
else
transform.Translate(Vector3.right * speed * hSign * Time.deltaTime);
}
// Forward Movement
if (fInput != 0)
{
if (Mathf.Abs(fInput) <= Mathf.Abs(hInput))
transform.Translate(Vector3.forward * speed * fInput * Time.deltaTime);
else
transform.Translate(Vector3.forward * speed * fSign * Time.deltaTime);
}
(As a note, I’m currently using a rigidbody but I want to switch to using a character controller. Also, sorry if my code is a little wack. I’m new to Unity and I’m transitioning from java to C#.)