Search Unity

Player Can't Jump On A Specifically Sized Cube

Discussion in 'Physics' started by Duetschbag, Dec 12, 2018.

  1. Duetschbag

    Duetschbag

    Joined:
    Jun 12, 2014
    Posts:
    10
    I'm playing around with creating a 3D platformer level. I started off with a plane, built the level with some other cubes and enemies and it works just fine. I then decided to remove the plane and use a cube at the main platform instead. If I set the cube transform scale to 10x7x10, my player can jump around and do what its supposed to so that it can complete the level (just like when I was using the plane). However, if I set the cube scale to 10x10x10, which is my preferred size, my player won't jump anymore. I can still move in all four directions with WASD, but cannot jump. I'm completely stumped by this.

    In actuality, if I set the Y scale to anything 7.98 or higher, that's when it stops working. 7.97 still allows my player to jump. The top of the cube, where the player stands, is in the same location no matter the Y scale. I've confirmed that no colliders are in the way of my character. I should also note that regardless of what this cubes scale is, if I move my character to other smaller cubes (via the editor) and jump around, the player is successful. But once I touch the 10x10x10 cube, the player can't jump anymore.

    I feel like this is something that sounds like a relatively easy fix, but I'm completely stumped. Anyone with any ideas?
     
  2. JuozasK

    JuozasK

    Unity Technologies

    Joined:
    Mar 23, 2017
    Posts:
    84
    Heya!

    What's your script for jump handling? How do you determine if the character is on the ground?
     
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Show us your code.

    Also, to my understanding messing with the transform scale on physics-related objects is a no-go, you have the size component on the cube collider and you can stick a graphic in a child object that matches the bounds of the box
     
  4. Duetschbag

    Duetschbag

    Joined:
    Jun 12, 2014
    Posts:
    10
    Thank you for the responses. I think @WashingMachine nailed it. See, I knew it would be easy! :)

    What happened, was when checking the location of the transform, my Y value (shown below) must have tricked my check into thinking that either the player is not on the ground or that my player was already jumping. By adjusting that to .001f, the issue doesn't occur.

    I'm going to add some debug steps and see where the actual issue is caused and then fix it up from there.

    Thanks again!

    Code (CSharp):
    1. Vector3 corner1 = transform.position + new Vector3(size.x / 2, -size.y / 2 + 0.01f, size.z / 2);
    2.         Vector3 corner2 = transform.position + new Vector3(-size.x / 2, -size.y / 2 + 0.01f, size.z / 2);
    3.         Vector3 corner3 = transform.position + new Vector3(size.x / 2, -size.y / 2 + 0.01f, -size.z / 2);
    4.         Vector3 corner4 = transform.position + new Vector3(-size.x / 2, -size.y / 2 + 0.01f, -size.z / 2);