I have a weird issue with the code below where movement on the z “vertical” axis does not occur.
the Debug logs show me that the input manager is working perfectly. the vertical inputs produce either -1 or +1 but the object only responds to the horizontal inputs.
If i comment out the xPlayerMove(); in update function then verticle movement on zPlayerMove(); works just fine. Any Ideas? Also, please see my input manager at the bottom. Cheers.
public class ExampleCode: MonoBehaviour
{
[Tooltip("In ms^-1, total normal spped")] [SerializeField] float normalPanSpeed = 20f;
[Tooltip("In ms^-1, total boosted speed")] [SerializeField] float boostPanSpeed = 40f;
float panSpeed;
float xThrow, zThrow;
Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Input.GetButton("Boost Pan Speed"))
{
panSpeed = boostPanSpeed;
}
else
{
panSpeed = normalPanSpeed;
}
zPlayerMove();
xPlayerMove();
}
private void zPlayerMove()
{
zThrow = Input.GetAxis("Vertical");
Debug.Log(zThrow);
rb.velocity = transform.forward * (zThrow * panSpeed);
}
private void xPlayerMove()
{
xThrow = Input.GetAxis("Horizontal");
Debug.Log(xThrow);
rb.velocity = transform.right * (xThrow * panSpeed);
}
}