I’ve just gotten started with Unity, and I’ve been working on some basic 3D first-person controls and movement. The problem I’ve been struggling with is how to incorporate jumping without the y vector being counted as part of the final normalized movement vector. In other words, how can I keep an accurate diagonal speed without jumping having an effect?
I want to be able to jump while traveling in any direction on the x-z plane without my horizontal speed changing.
A stripped down version of my script with the general ideas:
float forwardSpeed = Input.GetAxisRaw ("Vertical") * speed;
float strafeSpeed = Input.GetAxisRaw ("Horizontal") * speed;
Vector3 movement = new Vector3(strafeSpeed, 0, forwardSpeed);
if (Input.GetButton ("Jump")) {
movement.y = jumpSpeed;
}
Player.Move (movement.normalized * Time.deltaTime);