jumping glitch

hello there I’m trying to make an iPhone platform game and I have setup 3 GUI buttons. If you press them they will make the player can either move left right or jump. I have a strange problem with jumping though, every second jump or when a i’ve pressed the jump button 2, 4 , 10, 16 times my player barely jumps at all but if i’ve pressed it 1, 3 , 5 times it jumps it required jump height that i’ve set it to. Hope this makes sense. This problem is very strange and I don’t know why this is happening. Any help would be highly appreciated :slight_smile:

The for GUI buttons :

#pragma strict

var isMovingLeft = false;
var isMovingRight = false;
var isJumping = false;


function OnGUI () { 



if(GUI.RepeatButton(new Rect(300,250,80,50),"Left")){

isMovingLeft = true;

  }else{

isMovingLeft = false;

 } 

 
 
if(GUI.RepeatButton(new Rect(400,250,80,50),"right")){
   
 isMovingRight = true; 
   
 }else{

isMovingRight = false;

 } 
 
 if(GUI.RepeatButton(new Rect(365,220,50,20),"jump")){
 
   isJumping = true; 
    
   }else{

   isJumping = false;

 } 
 
}

and for the player :

#pragma strict

var movement : Vector3 = Vector3.zero;


function Update () {

var controller : CharacterController = GetComponent(CharacterController);
    

if (GameObject.Find("Camera").GetComponent(buttons).isMovingLeft){ //will check if true
 
transform.position -= Vector3.right * 2 * Time.deltaTime;
 
 }
 
 if (GameObject.Find("Camera").GetComponent(buttons).isMovingRight){ //will check if true

transform.position += Vector3.right * 2 * Time.deltaTime;
 
 } 
 
 if (GameObject.Find("Camera").GetComponent(buttons).isJumping && controller.isGrounded){ //will check if true

movement.y += 13;
 
 }
 
 if(controller.isGrounded == false){
 
movement.y += Physics.gravity.y * Time.deltaTime; 

 }
 
 controller.Move(movement * Time.deltaTime);
 
} 

thanks :slight_smile:

I assume you have some moments when the character is falling. The movement.y value will go down and become negative because you are ungrounded. Then when you jump, you only += 13 to it, and you may only become barely positive in movement.y. That’s why you see it every other jump. Just set the value of y to 13 instead of +=. It’s a velocity, so you should zero it out when you are grounded, or at least only set it to gravity for the frme.

Also, I would recommend using Camera.main instead of Find(). At a minimum, don’t call Find multiple times, et the result to a variable.