Player Character Never Grounded

Completely new here and will appreciate any and all advice given. My problem is I have a character that jumps but I would like it for her to only jump when she is standing on a platform. The problem is the code as I have it set up will always say she’s on a platform, even when she’s not. Here is my code:

var worldMouseDownPosition : Vector2;
var worldMouseUpPosition : Vector2;
var velocity : float;
var jumpForceMultiplier = 500;
var isFalling = true;
var readyToJump = false;

function Update () {
	if (Input.GetButtonUp("Fire1") && isFalling==false && readyToJump==true){
		worldMouseUpPosition = Camera.main.ScreenToWorldPoint (Input.mousePosition);
		gameObject.rigidbody2D.AddForce((worldMouseUpPosition - worldMouseDownPosition)*jumpForceMultiplier);
		readyToJump = false;
		isFalling = true;
	}
}

function OnCollisionStay2D(){
isFalling = false;
}

function OnMouseDown () {
	if (isFalling==false){
		worldMouseDownPosition = Camera.main.ScreenToWorldPoint (Input.mousePosition);
		readyToJump = true;
	}
	if (Input.GetButtonUp("Fire1")){
		readyToJump = false;
	}
}

Thank you for your help. Any unrelated tips also welcome!

My advice is that you should make the jump control into a Trigger Event. (I’m not that great with them so I recommend you use a tutorial video on youtube or something) But you can make a plane and use that plane as the trigger event and anytime the player is on that plane the trigger allows you to jump. theres more specific ways of doing it but thats my advice! :slight_smile: Goodluck! sorry I wasn’t that helpful.

Try this, but instead of using onCollision, try using onTriggerStay. Remember to add a secondary collider2d on with is trigger option checked on your character/player.

var jumping : boolean;
var jump : KeyCode;


function Update () 
{
   if(!jumping && Input.GetKeyDown(jump)) {
      rigidbody2D.velocity.y = 5;
      jumping = true;
   }
}


function OnTriggerStay2D (hitInfo: Collider2D)
{
   if(hitInfo.name == "platform") {	//name of your platform or ground
      jumping = false;
   }
}