[Solved] Efficient method to have multiple enemies use a single collision box object?

0 favourites
  • 9 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Hey everyone :)

    I'm having a bit of trouble with enemies falling through JumpThru Platforms when switching to their Attack State/Animation(or any State/Animation for that matter). As every animation frame is a different size, either a collision box or Origin Point is pushing them down into the JumpThrus.

    So, I've decided to set them up a similar way as my Player.

    My Player has a basic PlayerBox Sprite, Then has the Player Object with all it's animations set to the PlayerBox X & Y, then set it as a child of that object at the start of each layout.

    I'm having a bit of trouble puzzling this out for the enemies, as I currently have 4 platform enemies, and looking to expand on the amount of enemies. I'd like to have all the platform enemies use a single PlatformEnemyBox Object to handle the collisions. I've tried multiple ways to handle this issue.

    At the moment, I'm over complicating the issue like I always do. I tend to over analyze, and over complicate things... I'm currently trying create each Enemy Type on different instances of the PlatformEnemyBox Object by using a variable. I'm stuck going around in circles. I'm assuming to do it in this way. I would need to do the following.

    - Create a Global String Variable

    - At start of Layout, change that Global Variable to each enemy type's name(somehow)

    - Then On Start Of Layout > For Each PlatformEnemyBox > System > Create Object > Call that Global Variable to create the proper enemy type for each instance of the PlatformEnemyBox

    I'm basically been trying to set it up the same way as my player. But, as it stands, there has been no point in using the family object, because I haven't sorted out a way to create the proper enemy type on each enemy box using variables. So I've basically switched out the Enemies in the Family, with Boxes using a naming convention of "(EnemyNameHere)Box". Then Start of Layout, create the proper EnemyName for each EnemyNameBox.

    So I'm still doing excessive work with many different Actions/Events for each EnemyNameBox in the Family. It somewhat works, but it's not mirroring them the same way as it was before. I'd rather be able to use just one box for each enemy type in the family, without having 4 separate boxes in the family. Causing unnecessary use of Actions/Events, making using a Family Object Pointless.

    I've got a hot fix at the moment, so when any enemy in the PlatformEnemies Family goes into any other State, it sets the Platform Gravity to "0". Then when the Player goes out of their Line of Sight, they switch back to their Walking state, and go right back to walking on the JumpThru style platforms.

    This works just fine for the time being. But, I feel like it would be better in the long run to have a single collision box object, like what I'm doing with the Player & PlayerBox.

  • Have an instance variable on the enemy box which is the enemy type. Create an enemy based on the variable on the enemy box and pin it.

  • Have an instance variable on the enemy box which is the enemy type. Create an enemy based on the variable on the enemy box and pin it.

    Thanks lionz :)

    I'm going to set about testing that. I tried this earlier, but must have been doing something wrong. The enemy box becomes the platform object, and call the enemies from the Family Object? Using PlatformEnemies.ObjectTypeName

  • Okay. I've got it working with a couple different enemies. I'm going to have to rework a bunch of Instance Variables/Behaviours/Actions/Events, but I think this will wind up working much better than before.

    Thanks again lionz, I appreciate you taking the time to read, and respond :)

    Basically going to change the On Start of Layout, to have four sub-events checking for that instance variable, then create the proper enemy, pin it, then setup the debug text and whatnot I had on them before.

  • Nice :) Or another option if the enemies already exist in the editor, you can just set it all up in the editor and then pin with events. That depends on the design and if enemies exist before or if there are spawn points.

    You wouldn't use the family, I would think you need to create the specific object, you can use the create by name action.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Nice :) Or another option if the enemies already exist in the editor, you can just set it all up in the editor and then pin with events. That depends on the design and if enemies exist before or if there are spawn points.

    You wouldn't use the family, I would think you need to create the specific object, you can use the create by name action.

    Hmmm, interesting. Yeah, they are all already in the editor. I'm taking a break from that project for the time being. I've got it working. But, I setup the family to cut down on Actions/Events. The only issue was them falling through JumpThru Platforms while changing animations. I've got them setting up similar to the Player at this point. Putting the boxes in, and then creating the enemy type object.

    Screenshot below. If you know a better way to do this, I'm all ears haha. Luckily Construct makes it easy to swap out objects across multiple blocks. I was trying to just create the EnemyBox at every object from the Enemy Family, and pin it at start of layout. But, they were still falling through the JumpThrus.

    The plan was going to be. Move all the Behaviors, and instance variables to the PlatformEnemyBox. And just have a couple on the PlatformEnemy Family. This is how I have the player working. The event sheet in the screenshot is a mess, because it's right in between switching everything over. I disabled a bunch of stuff just to test and see if this method would work.

    I'm stuck between going this route, and falling back to my older save, which had the hotfix of setting gravity to 0. That one worked flawless. But thought, this may work better as I add onto the enemy states, and abilities.

  • Just for reference, this is my Event Sheet with that hot fix, just setting gravity to 0. Each enemy stops in it's tracks. Faces the player and plays attack animation, until losing LoS. Which is what I was going for. Then when losing LoS, they move back to Walking.

  • In general yeah the family is good to use, I just meant for the creation of those enemies. Based on the logic such as setting enemy animation based on enemy box variable you could put enemy and enemy box in a container. Using a container here means that the enemy for animations would be created automatically for each enemy box and they are always related to each other.

  • In general yeah the family is good to use, I just meant for the creation of those enemies. Based on the logic such as setting enemy animation based on enemy box variable you could put enemy and enemy box in a container. Using a container here means that the enemy for animations would be created automatically for each enemy box and they are always related to each other.

    Okay. That makes a bit more sense, now that you mentioned containers. All I know is they setup a parent/child type objects automatically, and can house multiple objects. More or less...

    I just started utilizing the Family Object. I'll spend some time tonight and study up on Containers as well. Then make another copy to test that method out as well.

    Thanks for your time, and all the useful input today. I really appreciate it.

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