Player is given opportunities occasionally to jump really high, Can't seem to figure out why.

Hi, I am noticing my player jumping hundreds of units up in my game when jumping up blocks (yes blocks its a sandbox game).

I don’t know what is causing this at all, but I will tell how I make jumping reoccur.

I tried fixing it by reducing the triggers’ sizes, but that didn’t help. I will leave a project link below.

1 player jumps
2 player lands
3 the surfaces of meshes are separated as separate meshes, and tagged with trigger colliders as “Block Top”
4 the player has an OnCollisionStay function that recognizes these surfaces

Also, while I’m positing, I’d really like to know a better way to do this. Please comment your suggestions.

https://drive.google.com/file/d/0B2ZiQtohl3tmTE1HaWVtUlVTVW8/view?usp=sharing

Hey man, I made some alterations in your script, removed the collider that was on the top of the block, created a layer to your block and resized the box collider of the player.

Take a look in the script:

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

	public float Speed;
	public float LookSpeed;
	public int LookRange;
	public float JumpForce;
	public LayerMask whatIsGround;

	private float MouseX;
	private float MouseY;
	public Transform groundCheck;
	private bool grounded;
	private float radius = 0.1f;
	private Rigidbody rb;


	void Awake()
	{
		rb = GetComponent<Rigidbody>();
		if(!rb)
		{
			Debug.Log("Cant find Rigidbody!");
		}
	}

	void FixedUpdate () {

		Collider[] whatIHit = Physics.OverlapSphere(groundCheck.position, radius, whatIsGround);
		for(int i = 0; i < whatIHit.Length; i++)
		{
			if(whatIHit*.CompareTag("Block"))*
  •  	{*
    
  •  		grounded = true;*
    
  •  	}*
    
  •  	else*
    
  •  	{*
    
  •  		grounded = false;*
    
  •  	}*
    
  •  }*
    
  •  // WASD Movement*
    
  •  if (Input.GetKey (KeyCode.W))*
    
  •  {*
    

_ transform.position += transform.forward * Speed * Time.deltaTime;_

  •  }*
    
  •  if (Input.GetKey (KeyCode.A))*
    
  •  {*
    

_ transform.position -= transform.right * Speed * Time.deltaTime;_

  •  }*
    
  •  if (Input.GetKey (KeyCode.S))*
    
  •  {*
    

_ transform.position -= transform.forward * Speed * Time.deltaTime;_

  •  }*
    
  •  if (Input.GetKey (KeyCode.D))*
    
  •  {*
    

_ transform.position += transform.right * Speed * Time.deltaTime;_

  •  }*
    
  •  // Mouse Look*
    

_ MouseX += Input.GetAxis (“Mouse X”) * LookSpeed * Time.deltaTime;_

  •  transform.rotation = Quaternion.Euler (0, MouseX, 0);*
    

_ MouseY -= Input.GetAxis (“Mouse Y”) * LookSpeed * Time.deltaTime;_

  •  MouseY = Mathf.Clamp (MouseY, -LookRange / 2, LookRange / 2);*
    
  •  Camera.main.transform.localRotation = Quaternion.Euler (MouseY, 0, 0);*
    
  •  // Jumping*
    
  •  if (Input.GetKey (KeyCode.Space) && grounded && rb.velocity.y ==0)*
    
  •  {*
    

_ rb.velocity += Vector3.up * JumpForce;_

  •  	grounded = false;*
    
  •  }*
    
  • }*

  • void OnDrawGizmosSelected()*

  • {*

  •  Gizmos.color = Color.green;*
    
  •  Gizmos.DrawWireSphere(groundCheck.position, radius);*
    
  • }*
    }

Tip: When do you want your player to react with physics dont move him with transform, later you will see strange movements of your character.
Another Tip: Try to not use GetComponnent inside Update function, for performance reasons.
Ask me anything in the comments, I will try understand(I don’t speak english too much) and try explain.