1. Hey Guest! Our new game Wargroove has released! Check out the forums or wiki for more information!
    Dismiss Notice

Tutorial Advanced Object Placement ( zLevel / renderLayer / Spaces / Anchor )

Discussion in 'Starbound Modding' started by Charlatan, Feb 10, 2017.

  1. AmazonValkyrie

    AmazonValkyrie Giant Laser Beams

    Really appreciating this tutorial, @Charlatan! It’s definitely helping me create some dynamic objects! Many thanks!
     
    Charlatan likes this.
  2. sarcose

    sarcose Scruffy Nerf-Herder

    Hey guys, I hate to necrobump this, but it's the apparently the most comprehensive guide on this subject. I'm trying to create an object with partial collision, and the use of both "spaces" and "spaceScan" has resulted in incomplete results - in both cases, the orientation breaks the collision in some way.

    I'm too lazy to find an imagehost, so here's a link to the image on my dropbox:

    https://www.dropbox.com/s/ea80my0ww4m4fqm/tw222.png?dl=0


    "orientations" : [
    {
    "dualImage" : "/objects/trickwalls/tw222.png",
    "imagePosition" : [0, 0],
    "frames" : 1,
    "animationCycle" : 1.0,
    "anchors" : [ "background" ],
    "renderLayer" : "foregroundEntity",
    "spaces" : [[0,0],[0,1],[1,0],[1,1]],
    "collision" : "solid"
    }
    ],
    Objects:
    https://www.dropbox.com/s/ii7n5ztdofdhb8a/spaces placed.png?dl=0

    Collision:
    https://www.dropbox.com/s/xyfz5vecat44m5n/spaces tested.png?dl=0


    With this, the left half of the image is solid no matter the orientation - in otherwords, when it's turned the other direction, the nonsolid portion of the image is the part that is solid. Is there some kind of spaces_left, spaces_right? or something else?


    "orientations" : [
    {
    "dualImage" : "/objects/trickwalls/tw222.png",
    "imagePosition" : [0, 0],
    "frames" : 1,
    "animationCycle" : 1.0,
    "anchors" : [ "background" ],
    "renderLayer" : "foregroundEntity",
    "spaceScan" : 0.99,
    "collision" : "solid"
    }
    ],

    Objects:
    https://www.dropbox.com/s/x1bg8ngpra5mebk/spaceScan99 placed.png?dl=0

    Collision
    https://www.dropbox.com/s/5p3rp6xefz5mx7h/spaceScan 99 tested.png?dl=0


    And with spaceScan, the image correctly handles collision in one orientation and not the other. When it faces left, it's correct. When it faces right, there is an extra block that's solid. I imagine this might have to do with imagePosition? In that case, there's no imagePosition setting I can use that wouldn't produce an errant solid block in some orientation, as there is meant to be more nonsolid space than solid space, which means there wouldn't ever be a block in the dead center that could be solid.

    The spaces method is obviously preferred for something like this (there will be many different configurations of this kind of item in the mod), as I suspect the spaceScan problem is not as easily solveable.

    If there's a lua solution, what's the method for retrieving an object's orientation?
     
  3. bk3k

    bk3k Oxygen Tank

    Besides "spaces" there is "collisionSpaces" that can be used. That can even be used while using "spaceScan". But your solution should be using 2 orientations instead of one. A left hand one and a right hand one. Each one with their own independent spaces defined.

    Look at /objects/ancient/ancientconsole/ancientconsole.object

    As for your lua question, object.direction() or objectAnimator.direction() would work tell you what direction you're facing.
    You can even modify the collisions on the fly with object.setMaterialSpaces()
    The doors would be the best example of this as they place invisible metamaterials when closed and remove them when open.
     
  4. Charlatan

    Charlatan Parsec Taste Tester

    I'm glad if this is necro'd, as it seems to help people understand these mechanics ^^.

    First of all your problem with the more automatic method "SpaceScan" is VERY odd. Spacescan directly creates collision according to how much one block (8x8 pixels) is filled in your .png file. At the very least, the extra collision block should exist in both orientations then.

    Could it be that your .png has, where the strange invisible block is located, some semi-transparent pixels?

    As for separating the orientations, your orientation block can have two entries for left and right, the option you use then is called:

    " "direction" : "right", " or " "direction" : "left", "

    like this:

    For both blocks, you can set different Spaces and collisionSpaces.
     
  5. sarcose

    sarcose Scruffy Nerf-Herder

    Alright thanks to both of your responses, that's a lot of good info! I was having a hard time finding the exact methods I needed. I'll respond a bit later once I have a chance to test these out.

    As to the image itself, there aren't any transparent pixels or anything - I tweaked and tweaked and tweaked that blue outline thing to try and reduce its pixel coverage. I still think there must be something to do with imagePosition perhaps - that it represents the 0,0 "anchor" or something. But either way, using left and right should fix that issue too, I assume.

    Oh, and the reason the object looks so strange is because you're supposed to place it and it'll disguise itself as the background blocks, hiding whatever is in the blue outline like a hidden wall
     
  6. sarcose

    sarcose Scruffy Nerf-Herder

    Alright so I tested it out with direction : left and direction : right, with separate orientations. It still gave me a "mystery collision" block, so I played with imagePosition on the left orientation, and setting it to [-16, 0] fixed the issue. I think this goes back to your original guide where you mentioned that, upon removing all collision and anchors, there still has to be a single block that can't be placed over - clearly the position of this block is set by imagePosition. I'm guessing a lot of modders don't use spaceScan for objects with such a clear separation of collision, or that a lot of modders tend to copy/paste objects with an imagePosition.

    Piggybacking off of that, if I set imagePosition in both left and right to -16,0 (if I just used what seems to be the standard for a lot of the vanilla objects), the "mystery block" appears in the right orientation instead. Since there's an even number of blocks and collision/noncollision is split halfway, there can't be a center block for the anchor to hide in, so I have to use two separate imagePositions.

    Again, this is all with spaceScan. I didn't test it with spaces - but spaceScan with separate imagePositions works perfectly.

    Thanks for the recommendations guys!
     
  7. projectmayhem

    projectmayhem Ketchup Robot

    I dont know if you do this when testing your mod, but while in /admin mode, you can type /debug and /boxes to see all the space you object takes up, I used this for the first time the other day. I did notice, that there was 1 box that wasnt with the rest of my object, it seems to be the anchor point. I was able to move this anchor point around in my "animationPosition" part of my object file. Dont know if this will help you , but at least if you didnt know about the /debug and /boxes , using those may help
     
  8. Charlatan

    Charlatan Parsec Taste Tester

    I'm glad it works now!

    Also: No problem ^^ to be honest, I for my part learned something new from what you said here!

    The "central" block of an object and upon which imagePosition's coordinates is used indeed very likely indeed has a "default" collision block EVEN if you gave it a different, valid collision already.

    When I get back to adding new content to my mod, I will test this (though I am quite sure already your thought is correct) and add it to the tutorial !
    Just to be sure I'd still keep an eye out, Ghost Blocks ? :eek: Spooky, but at least they're not Erechius :confused:
     
  9. ChangelingRain

    ChangelingRain Subatomic Cosmonaut

    This is technically a necro but I have some sort-of useful information - the renderLayer for liquids is Liquid, which is above ItemDrop and below FrontParticle.

    Still no idea what the renderLayer for actual blocks is though!
     
  10. DShakaL

    DShakaL Subatomic Cosmonaut

    I want to place stools in front of a stove with a table, but the "renderLayer" parameter stubbornly refuses to work. Maybe I'm doing something wrong?

    {
    "objectName" : "dslshipstool",
    "colonyTags" : ["ancient"],
    "rarity" : "essential",
    "category" : "furniture",
    "price" : 200,
    "description" : "Ship stool.",
    "shortdescription" : "Spaceship Stool",

    "apexDescription" : "It's just a stool.",
    "avianDescription" : "A stool. I could do with sitting down.",
    "floranDescription" : "A round ssstool! Floran can ssspin on it! Dizzy fun.",
    "glitchDescription" : "Unimpressed. The metal on that stool needs a polish.",
    "humanDescription" : "Just like the stools back home.",
    "hylotlDescription" : "A rather typical seat found in spaceships.",
    "novakidDescription" : "A stool. I'm familiar with these. Too familiar.",

    "inventoryIcon" : "dslshipstoolicon.png",
    "orientations" : [
    {
    "dualImage" : "dslshipstool.png:<color>",
    "imagePosition" : [-8, 0],
    "frames" : 1,
    "animationCycle" : 0.5,

    "spaceScan" : 0.1,
    "anchors" : [ "bottom" ],
    "renderLayer" : "Object+10"
    }
    ],

    "objectType" : "loungeable",
    "sitFlipDirection" : false,
    "sitPosition" : [0, 22]

    }
     

    Attached Files:

  11. rin_elyran

    rin_elyran Void-Bound Voyager

    I'd like to thank you very much for this very informative thread; it's definitely helpful for the progression of a personal mod pack I'm working on to help me hone my coding skills.

    Part of my pack involves modifying selected material blocks so that they appear on the layer immediately in front of the player (i.e. "renderLayer" : "player+1"), so I added this bit of code to the Orientations section of a test object and, just as I had hoped, I could walk behind said object. Then I got to thinking that I could integrate hidden passages into my builds with this method, during normal gameplay.

    Once again, thank you so much for this thread. I'd be lost without people like you. :D
     
    Last edited: May 19, 2019 at 11:13 PM

Share This Page