Search Unity

2D Platformer Jumping Error

Discussion in 'Scripting' started by PhysicalBeef, Sep 20, 2014.

  1. PhysicalBeef

    PhysicalBeef

    Joined:
    Jun 13, 2013
    Posts:
    150
    So, everything works fine, but 1 thing. Jumping from connected blocks above ground.




    Now, as you can see on the picture, the green blobs represent the player, and the black lines is the jumping height. Now, when you jump on top of the connected row of blocks, as you can see, you can't jump far. When I disconnected a block from the group, you could. Lone blocks: high, Multiple blocks: Low.

    How can I fix this?

    Jumping function:
    Code (js):
    vv that line is lying..
    Code (csharp):
    1.  
    2.  if(Input.GetKeyDown(KeyCode.Space) && grounded || Input.GetKeyDown("w") && grounded) {
    3.         grounded = false;
    4.         Jump();
    5.         }
    6.     }
    7.  
    8. //------------------------
    9.  
    10.  
    11. function Jump() {
    12.     audio.PlayOneShot(jumpSound);
    13.     rigidbody.AddForce(Vector3.up * 1000);
    14. }
    15.  
    16.  


    upload_2014-9-20_19-4-33.png
     
  2. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    There is not enough information available to troubleshoot the problem.

    What are the specifics for your jumping control, forces and collisions implementations?

    Based on the limited information provided I would guess that possibly you have some kind of stickiness on a block. The forces of this stickiness are "holding" the player. When two blocks are involved as illustrated in your screenshot it appears the player is actually on top of two different blocks at the same time and perhaps the "sticky" force being applied is double the amount compared to the sticky force being applied from only one block.

    That may be completely off. Like I said, it is just a "best guess" based on the limited information available.
     
  3. PhysicalBeef

    PhysicalBeef

    Joined:
    Jun 13, 2013
    Posts:
    150
    connected blocks.png disconnected blocks.png





    Well, if you want to ill pm you the script. (its really good, and i'd want to keep it for myself) but heres basically what happens.. kind of.
     
    Last edited: Sep 20, 2014
  4. PhysicalBeef

    PhysicalBeef

    Joined:
    Jun 13, 2013
    Posts:
    150
    Can't anyone help? Please, I'd really need some help :(
     
  5. BmxGrilled

    BmxGrilled

    Joined:
    Jan 27, 2014
    Posts:
    239
    We need to know more about what you're expecting to happen, and what's going wrong?!
     
  6. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    If you don't want to share the scripts or parts of it, you'll rather have to work with a lot of Debug.Logs on your variables (or print them with the GUI system) so that you can get a basic idea about what's actually going on.

    As soon as you find values that you didn't expect (for instance, your jump height is totally messed up), you can get step by step closer to the actual problem.
     
    Last edited: Sep 21, 2014
  7. PhysicalBeef

    PhysicalBeef

    Joined:
    Jun 13, 2013
    Posts:
    150
  8. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Still no idea, you'll have to work with Debug.Logs on your own. Check the values which are involved in your jumping system and try to find out which part of your code limits the jumping height.

    That's all i can (still) recommend and i doubt anyone else can help you there without having more information about your code.
     
  9. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    If the scripts are that good they would be working, post code and this will go twice as quickly.
     
  10. Limeoats

    Limeoats

    Joined:
    Aug 6, 2014
    Posts:
    104
    As some have said above, the only ways you are going to solve this issue are either by posting the entire script, or doing the debugging yourself. I'm assuming that since you posted here, you want our help. If that is the case, then just post the script and we will be able to help you.
    If not, do your debugging with Debug.Log. In your player's update method, print out the force being applied to his rigidbody every frame. Maybe print out which blocks are being collided with every frame.
    There are many different variables that could be causing your issue, and the only way to figure out which one is the problem is to print out all of these values and see which one looks off. Then, you can investigate that specific element further to figure out how to fix it.