The logics behind Bounding boxes of movement settings

Discussion in 'Starbound Modding' started by telles0808, Feb 13, 2014.

Thread Status:
Not open for further replies.
  1. telles0808

    telles0808 Scruffy Nerf-Herder

    The logics behind Bounding boxes of movement settings

    After blaming myself because of detection issues, I released the most important part of movement detection.

    While researching for tips, it's possible to recognize a Chicken as one of the smallest monsters in the game, so, looking inside it's code, you're able to see the collisionPoly setup saying to the game:

    - Hey dude, make a collision polygonal mask around me, starting from the first point at -1.0 in X and -1.0 in Y, and keep doing the follow ordinary points.
    Code:
        "movementSettings" : {
          "collisionPoly" : [ [-1.0, -1.0], [1.0, -1.0], [1.0, 1.0], [-1.0, 1.0] ],
          "mass" : 1.0,
          "walkSpeed" : 7,
          "runSpeed" :15,
          "jumpSpeed" : 10,
          "flySpeed" : 15,
          "airFriction" : 0.15,
          "airForce" : 100.0
        },
    So, you can release, whoah! That's cleaver! Making a collision mask around my custom monster, NPC, or pet will give to the game the possibility of detect the size of my sprite and check if it hit a block, right?

    Well, the saddest part is the true, it won't work in any case. Let's figure out a frame with 48x64 pixels of size, instead of 16x16 from our chicken.

    When you release your brand new thing in the game, it will show a misalignment of 400% and don't ask me why I know it, was a pure intuition and feeling. Now, it's easy to figure out how we can align that thing inside the game:

    Simple div your size 48 by 16, so, 48/16 = 3, and you'll have the magic number to place inside the collisionPoly, do the same for the height, 64/16 = 4, and so on.

    Code:
        "movementSettings" : {
          "collisionPoly" : [ [-3.0, -4.0], [3.0, -4.0], [3.0, 4.0], [-3.0, 4.0] ],
          "mass" : 1.0,
          "walkSpeed" : 7,
          "runSpeed" :15,
          "jumpSpeed" : 10,
          "flySpeed" : 15,
          "airFriction" : 0.15,
          "airForce" : 100.0
        },
     
    Julyuary, Aurorialis and The | Suit like this.
  2. Aurorialis

    Aurorialis Pangalactic Porcupine

    Great info, telles!
     
  3. jokekid

    jokekid Space Spelunker

    so, everything needs to be a multiple of 16, always?
    or is it possible to use decimals?

    EDIT: also, this thread is being directed towards on a pinned thread, so i assume it's not considered necro?
     
  4. telles0808

    telles0808 Scruffy Nerf-Herder

    You can use decimal in the percentages, but think always on keep rounded sizes in pixel, because the game will round the size of the collision box it if you use fractions of pixel sizes, making, for example, your object go inside the ground.
     
  5. Rufran

    Rufran Subatomic Cosmonaut

    So, 1 unit of space is 8 pixels? -1 to 1 should be two units, right? I want to take the gnome art from the throw-able and make them into critters. They are 1x3 pixels. Does that mean I should be doing:

    "collisionPoly" : [ [0.0, -0.125], [0.0, -0.125], [0.0, 0.125], [0.0, 0.125] ],

    ?
     
    Last edited: May 18, 2016
  6. lazarus78

    lazarus78 The Waste of Time

    Yes, a value of 1 translates into 8 pixels on a tile. So IE 0.5 is equal to half a block, or 4 pixels.
     
Thread Status:
Not open for further replies.

Share This Page