How do I make my characters go behind buildings:

0 favourites
  • 13 posts
From the Asset Store
Be discreet and rescue your friends from behind enemy lines.
  • Hello,

    I am trying to make my characters go 'behind' a building when their Y is lower than the building's Y and higher then the building's X (Because my graphics are going to be oblique, it should look like they are going behind the building if they come at it from the right a bit).

    I've put all of my building objects on the one layer and into a family called f_perception, as well as my characters. I've got this code in place to send objects in front and behind:

    Please note: the Char_box_Helper is in a container with Char_Helper

    It works for some buildings and not others, and I don't know why.

    Can I get some help with this one please?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • wait no this one is better puu.sh/Cc6Jl/c7963ec2e1.c3p

  • See this demo I made for another post:

    dropbox.com/s/lbewjvv6rekd2na/IsometricForest.capx

    .

    Instead of sorting by Y on every tick it's better for performance to add an instance variable and use "System Sort Z Order".

  • Thanks to both of you for your help.

    Dop, I think performance will eventually become a priority in my project as it will be quite large. Is there a way I can incorporate your solution but say if I had other characters? yoyoEleanor's example perfectly orders everything correctly regardless what object it is, which is exactly what I'm after because there could be other characters moving around that should have their X and Y taken into account as well.

    Also, it should be easy to also add the condition that X of the character is higher than the building in order to put the character behind the building with your examples, right?

  • Yeah, yoyoEleanor's example is exactly what I meant. You add all sprites to a family, add an instance variable "zsorting" to this family and z-sort by this variable. You can set this variable to sprite.Y or use a different image point or some sophisticated formula. The only drawback of this method is that you can't sort a group of sprites and other objects (say, tiled backgrounds), as it's not possible to add them to one family.

  • Okay, thanks. I just have one more problem in regards to this issue:

    Person is underneath building. This is bad for buildings, but it's good when it comes to checking characters with characters.

    This is the good part about it, though:

    The person can go behind the building a bit on the right hand side.

    Now, I just need to consider the X value of the objects in the family. Here is the code at the moment:

    I have put the X value into an instance variable and an image point in the bottom corner of the building (this is the point I want to use to consider the Z order of objects), but I'm not sure how to get the family to consider the X value of all objects inside it. Every attempt I've made seems to not work properly.

    Is there a way to get all objects in the family to see if the X value is greater than the building before moving it behind it?

  • break it into multiple parts

  • Sorry I don't understand what that means.

  • I imagine something like this:

    Red and blue are two different sprites. Yellow dot is the "perception" image point.

  • If I did do that, it would solve the problem on the left hand side but not if the character comes from the footpath or the driveway, it would still look like they were underneath the building. I am trying to work out a way I can organise it with events but I keep running into road blocks at every turn.

  • Are you using 8-direction behavior to move the character? You need to set correct collision polygons for all sprites.

    Here is a demo, although it may be a bit buggy because all image points and collision polygons need to be set with pixel precision.

    dropbox.com/s/6num28c6nf9qhfb/ZOrderBuilding.capx

  • Yeah I am using 8-direction. Sorry I forgot to explain that.

    God I just love you and your ideas. I didn't really understand it at first but I do now.

    So I should be able to use my code to make this work.

    I just have a lot of buildings to put together with two pieces.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)