Character jumps unusually high near platform edges and unusually far when repeatedly tapping movement keys

So I’m figuring out Unity2D by piecing apart the documentation as well as the example that the Unity site has available.

Currently jumping is almost always proper except for two cases.

Case 1

The player jumps at the edge of a platform and jumps around 1.5 to 2x higher than normal. This is only recreatable at platform edge and I suspect it has to do with the fact that I’ve got the game coded to give the player 10 drag on the ground, and 0 drag in the air, I think it may be an inconsistency with Update and FixedUpdate and I’m not using them correctly.

Here’s code that I think’s relevant to the problem, the entire script I’ve written will be available at the bottom in a link.

void Start () {
		groundCheck = transform.Find ("groundCheck");
	}
	

	void Update () {
		 
		if (grounded && Input.GetButtonDown ("Jump")) {
			rigidbody2D.AddForce(new Vector2(0, 1000f));
		}
	}

void FixedUpdate () {
		grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));
		if(grounded)
			rigidbody2D.drag = 10;
		else
			rigidbody2D.drag = 0;
        ...
}

Case 2

This is the case where the character can go unusually far when jumping. It can happen regardless of where the player jumps, and cannot be recreated by tapping repeatedly while on the ground. It seems like the character gets a one frame acceleration before getting floored by the speed limit, but pressing fast enough it allows for a 1.5 increase in jump distance.

Again, part of the code that I suspect is relevant, whole thing available at the bottom.

void FixedUpdate () {
	grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));
	if(grounded)
		rigidbody2D.drag = 10;
	else
		rigidbody2D.drag = 0;
	float h = Input.GetAxis("Horizontal");
	if (Mathf.Abs(h * rigidbody2D.velocity.x) < 5f)
		rigidbody2D.AddForce (Vector2.right * 365f * h);
	if (Mathf.Abs (h * rigidbody2D.velocity.x) > 5f || Mathf.Abs (rigidbody2D.velocity.x) > 5f)
		rigidbody2D.velocity = new Vector2 (Mathf.Sign (rigidbody2D.velocity.x) * 5f, rigidbody2D.velocity.y);
    ...
}

Hopefully this is formatted well enough to be legible, here is the remainder of the code in the script.

http://pastebin.com/fADgCSR5

Okay, this is awkward because I fixed it myself, but for those curious.

Case 1

Okay definitely, keep your variables in the same Update loop as ANY LOGIC CASE THAT NEEDS IT. I just had to push them all into Update, and everything was fine.

Edit: Apparently it’s better to put them in FixedUpdate since they’re physics related.

Edit2: It causes other bugs to put a buttonpressdown in FixedUpdate, so I’m leaving it in Update since it has yet to fail there.

Case 2

I just had to add to my acceleration if statement an addendum of rigidbody2D.velocity.x < 5f to prevent going over the top (5f being the max).