- Home /
2D Player Movement
Hi I am trying to make a 2d side scroller similar to the old tutroial on the Unity website but not as complex. So, far I have run into quite a few problems with my movement code and I'm not sure what is wrong. Here is the code:
void FixedUpdate() { // Get the Vector3 for movement direction m_vMoveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0); m_vMoveDirection = transform.TransformDirection(m_vMoveDirection); // m_fCurrentMovementSpeed = 7.0f m_vMoveDirection *= m_fCurrentMovementSpeed;
m_vMoveDirection.y += m_fGravity * Time.deltaTime;
CharacterController _Controller = GetComponent<CharacterController>();
flags = _Controller.Move(m_vMoveDirection * Time.deltaTime);
m_bGrounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
this all works fine for moving on the positive X but when I try to move on the negative X it does nothing. Also, it worked correctly yesterday and as far as I know the only thing I have changed is saving and shutting down the program. Does anyone see any reason this should not work?
I don't see any obvious problems. You might try printing out the value returned by Input.GetAxis("Horizontal") to make sure it's in the range you're expecting.