AddForce from Two Sources

So in my game, the player controls through scripting. Particularly because I didn’t know the character controller component existed at the time, and when I learned about it, the script was too firmly rooted in the game to remove.

Anyways, I have a player movement script operating exactly the way it’s supposed to, with WASD controls. Here’s what they look like.

						if (Input.GetKey (KeyCode.A)) {
								rigidbody2D.AddForce (Vector2.right * -movement);
						if (Input.GetKey (KeyCode.W)) {
								rigidbody2D.AddForce (Vector2.up * movement);

No problem. However if I punch in A and W at the same time, the player moves diagonally. That’s fine, but the problem is that because force is being applied to the object from two sources, the object moves faster diagonally than it would if it were just the W or A key.

So anyone with a better grasp of coding than me know of a way to get the player to be pushed at speeds similar to normal movement speeds while both W & A are being pressed?

Try adding this after the end of your if conditions:

rigidbody2D.velocity = rigidbody2D.velocity.normalized * movement;