Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Infinite Jump Problem

Discussion in 'Android' started by betamech, Jun 29, 2014.

  1. betamech

    betamech

    Joined:
    Jun 27, 2014
    Posts:
    9
    This is not the usual double jump problem people have. I have a game which I started developing for PC and than I decided to switch to Android. Everything worked fine on PC but once I switched to Android the jump began giving me problems. The ball used to be able to jump once only but now it can jump in the air. Not the infinite type jumping into the sky but the ball is able to jump right before it hits the ground. If the ground is -20 in the y axis the ball is able to jump once it is in -19 in the y axis. Here is the ball control code :

    Code (JavaScript):
    1.  
    2. #pragma strict
    3. var rotationSpeed = 100;
    4. var jumpHeight = 5;
    5.  
    6. private var isFalling = false;
    7.  
    8. function Update () {
    9.  
    10.     //Handle ball rotation.
    11.     var rotation : float = Input.acceleration.x * rotationSpeed;
    12.     rotation *= Time.deltaTime;
    13.     rigidbody.AddRelativeTorque (Vector3.back * rotation);
    14.  
    15.     for (var touch : Touch in Input.touches) {
    16.         if((touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled) && Physics.Raycast(transform.position, -Vector3.up, 1) && isFalling == false){
    17.             rigidbody.velocity.y = jumpHeight;  
    18.         }
    19.     }
    20.  
    21. }
    22.  
    23. function OnCollisionStay (){
    24.  
    25.     isFalling = false;
    26.  
    27. }
     
  2. nburlock

    nburlock

    Joined:
    Apr 11, 2013
    Posts:
    65
    You could try putting your physics code into FixedUpdate() rather than Update().
     
  3. betamech

    betamech

    Joined:
    Jun 27, 2014
    Posts:
    9
    I'll try that thanks.
     
  4. betamech

    betamech

    Joined:
    Jun 27, 2014
    Posts:
    9
    That doesn't change anything.
     
  5. tobicreaper

    tobicreaper

    Joined:
    Apr 30, 2013
    Posts:
    69
    your "isFalling" is always false.. try putting "isFalling= true" inside your "if condition" right below "rigidbody.velocity.y= jumpHeight;"

    this might help.
     
  6. betamech

    betamech

    Joined:
    Jun 27, 2014
    Posts:
    9
    Still with the same problem. Thanks for trying.