- Home /
transformDirection goes to zero as I look upwards.
I'm trying to create a First Person controller using rigidbody.velocity. I am using camera.transformDirection to detect the direction in which the character moves. Everything works perfectly except as I look upwards, the x value of the vector 3 approaches zero. This means the character can't move when looking directly up. Maybe there is some way to ignore the y value. I'm not entirely sure but any help would be appreciated. Here is my code:
float front = Input.GetAxis("Vertical"); float side = Input.GetAxis("Horizontal"); Debug.Log(Forward); if (One == true) { Forward = Mcamera.transform.TransformDirection(Vector3.forward); Forward = Forward.normalized; } else{ Forward = Vector3.zero; } if (Three == true){ Left = Mcamera.transform.TransformDirection(Vector3.right); Left = Left.normalized; }else{ Left = Vector3.zero; } Forward = Forward.normalized; Vector3 move = new Vector3(front * Forward.x + side * Left.x , 0, front * Forward.z + side * Left.z); rb.velocity = move * speed;