Hello everyone,

I'm making a 2d game

I am using multimesh 2d to create thousands of objects, along with a 2d shader, to make animations, but I have the problem of how to perform z ordering, since using multimesh 2d there is no property that does it for each independent instance, some ah Have you had any luck implementing a system, or have any ideas on how it might be approached.

greetings

    gato1029 If the transform format is set to 3D, then instance z coordinate can be set and depth buffer should take care of ordering.

    hi, @xyz
    I have tried to put the multimesh in 3D, but when doing so it does not draw in the 2D environment, I am using godot 4, if you had a working example of how to parameterize it so that it takes it, I would be very grateful.

    greetings

    • xyz replied to this.

      gato1029 Hm, you're right. I guess the instances will be drawn in the order they're stored in the array. So you'll need to sort them manually. By which criteria you need them sorted?

      hi again @xyz
      The game I am making is isometric, and I would need to order it based on the height of the Y order, the detail is that I want to use multimesh to animate multiple instances, and since they are going to move throughout the entire map, they must be Sort according to height so that they do not overlap badly. Any idea how to do it.

      greetings

      • xyz replied to this.

        gato1029 Probably should use something other than multimesh for this. How many instances you need to have?

        I tweaked the tags to Godot Help 👍

        Thanks @MikeCL, @xyz for the answers I intend to have an average of 3000 to 4000 rendered animated instances on average, I plan to do something similar to they are the billions, where you have thousands of units.

        greetings

        • xyz replied to this.

          gato1029 you have to understand how multimesh works: it sends ONE mesh and an array of transforms to the GPU, and then the shader renders copies of it based on the transforms.
          It will ALWAYS render them in the order that they are set in the array.
          As you were told, a solution is to use 3D meshes, then they would be subject to the depth buffer and would render correctly.
          A solution for 2D is to use an algorithm in the script to swap transforms around depending on where they should be drawn.
          I would convert the entire game to 3D, multimesh works better in 3D and you can still use sprites and a ground, just set the camera to orthographic.

          Edit: use multimesh3D and sprites (quads) with alpha clip (scisor) and the thing that aligns them to the screen, I don't know if you can change the UVs of individual meshes, you should test this.
          In 2D, multimesh is going to render every single sprite on the screen because of draw order, but in 3D it can use the depth buffer with alphaclip, so it will be FAR more performant, specially if it renders the meshes in front first, because it will ignore the pixels of the ones behind.

          hello everyone,

          First of all, thank you for all the answers, yesterday I was playing with what you mentioned @Jesusemora, @xyz , taking everything to 3d and working there under 2d, in XY ordinates, and taking z as depth.

          And if it works to take it there, and I'm trying the issue of cutting each segment of the sprite now, with a little luck I'll get it out. 🙂

          There are many to implement such as collisions and agents under the 3D environment, but working with 2D in XY ordinates, I know it sounds complicated, but I find it fun and interesting, since it is creating the entire engine focused on what I need.

          In summary for some other poor unfortunate soul of the future, the simplest solution with Godot 4 currently, if you want to work with multimesh under a 2D environment and want to handle depth, take it to 3D and work there in an environment adapted to your need in XY ordinates .

          Thank you all for the answers.