pandabear7413's Forum Posts

  • If you are going to use many objects then it looks like you don't need to make a separate enemybox object for enemies, you should just use one object. I don't know what its use is but I can't imagine you need different objects.

    I was thinking the same thing. The enemyBox is just for positioning and movement, so I was first thinking to have a single enemyBox object with 1 animation (and collision polygon) per enemy type. But and you can't have an object (i.e., the enemyBox) belong to multiple containers, so instead I was planning to create an enemyBox object type for each enemy type and then put the 2 in a their own container. But since containers cant be used for families, it looks like the best option is to use my family of enemies with a single enemyBox object type, and tie the 2 together using a uniqueID instance variable.

    I got so excited when I saw what containers can do. I haven't use a scene graph object yet, do you know if that may be a good option for what I'm looking to do, and if it works with families?

    It's a bummer C3 doesn't support containers with families. Both features have significant benefits and if they worked together it could make the pick code more elegant and much less error prone. I spend a lot of my time debugging issues related to object selection. Thankfully folks like you have been very helpful when I run into problems!

  • You can't use families here because they don't relate to the containers. You need to just set position for things that are in a container. You don't need to use the variables either because the containers already do the work of linking them.

    So it looks like I lose the value of families if I use containers. For example, if I every want to change the text of an enemyLabel when I click on its enemy, I can't use this because it will change the text of EVERY enemyLabel:

    Instead, I need a block like this for EVERY enemy:

    Is this correct? If so, using containers+families is a non-starter, and I'll have to go back to using families and tying enemyBox objects to enemies using the uniqueID approach (groan).

  • Gotcha - so is this what you're suggesting? It works :)

    If I have 20 enemy types I'll have to do this for each type. Not a huge deal in this case, but I can't anticipate how often I'll have to do something similar for all enemies, and I want to be clean and efficient with my code if possible. If I use the containers+families approach, is there any way I can leverage the families to simplify container-related activities? I'm assuming 'no' per your response but making sure I'm not missing something.

    Thanks

  • In my platformer, I want each enemy sprite to have an enemyBox sprite to use for movement positioning, along with an enemyLabel text. To make things easier, I was hoping to use containers.

    Since an object can't be part of more than 1 container, and I have many different enemy objects, I can't just create a generic enemyBox sprite and add it to each enemy's container. Therefore I was planning to create 3 families: enemies, enemyBoxes, and enemyLabels. Then I would make individual containers for each enemy type. I.e., zombie, zombieBox, and zombieLabel would be 1 container.

    My prototype works except for the code that positions the enemy on the enemyBox. When pressing 'z' or 'w' to create the first enemy, it places it fine. If I continue to press the same key to create the same enemy type, the new enemies are created and placed as expected. But when I press the other key to create the other enemy type, the new enemyBox is created properly but the enemy is placed on the previously created enemyBox. Pic and c3p attached.

    What am I doing wrong here?

    Question 2: is using containers + families a good approach for what I'm looking to do, or is there a better way? I originally tried using a common instance variable called uniqueID to tie the different objects together, but I ran into picking inconsistencies. The container approach seemed like a promising solution, but this issue is giving me pause.

    Thanks

    https://drive.google.com/file/d/1glQSeDO72Fvi3SsmARA-Xsh_s_3nDdIJ/view?usp=sharing

  • Example - I want to find posts containing the text "enemy box". Here's one that should come up: https://www.construct.net/en/forum/construct-2/how-do-i-18/set-sprite-position-enemy-box-101414?kws=container

    But if I put in "enemy box", with or without quotes, in the "search this forum" textfield, I get 7995 results - but don't see "enemy box" in the titles in at least the first page. If I do the same using the 'search' link in the upper right and specify 'search titles', I get 2226 results, but don't see "enemy box" in the titles (it's probably there but on who knows what results page).

    Help?

  • In my code:

    When the spacebar is pressed an enemy object is created, a corresponding enemyBox is created as well. But the enemyBox.speedMultiplier instance variable isn't getting set to the enemies.speedMutliplier value and instead is set to the default value (1). It's almost as if the enemies.speedMutliplier value hasn't been completely set in the spawnEnemy function before the 'on created' block is called.

    Can someone please explain why this is happening? Maybe it's a synchronization issue? I admit I don't understand sync / async very well.

    https://drive.google.com/file/d/1hOtJEhgl5agAFPPgpA222me8YH86wrU0/view?usp=sharing

  • I'm getting back into C3 after a few months and I'm definitely rusty. I'm getting some inconsistency in my new code and I think I may be picking objects incorrectly...

    Each enemy in my platformer used to just be a sprite, but to make things smoother I'm adding logic for an enemyBox 'anchor' sprite used for positioning and smooth movement. Each enemy sprite will now have a corresponding enemyBox object. The enemy and enemyBox sprite objects both have an instance variable called uniqueID, and it's this variable that ties them together.

    What's the best way to pick the enemy and enemyBox objects that have the same uniqueID? For instance I want the following code to position the enemy where its enemyBox is, but in certain situations enemies are placed on the wrong enemyBox. I believe this code may sometimes be picking the wrong enemyBox or just picking one at random. Is this the right/best way to pick an enemy object AND enemyBox object that have the same uniqueID instance variable?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can set up 2 or as many los cones as you want...

    Ok now THAT I didn't know - gonna try it!

  • Thanks. The challenge I've had w/ the LOS cone is that it only works for forward facing enemies. I.e., if I set the cone to be in the direction the enemy is facing, I can basically walk up behind them and I won't be in their LOS.

    I'm trying to implement a somewhat intelligent enemy AI, specifically:

    - they'll 'see' me from far away if they're facing facing me

    - if they're not facing me, they'll 'see' me when I'm closer, but I don't need to be right on them

    - if I shoot them from behind, they instantly know I'm there, regardless of how far away from them I am

    I guess this isn't really what LOS behavior is meant to accomplish, and it's more useful when trying to hide behind solid objects, etc. Just wondering if I'm missing something.

  • In my platformer game, I want the enemies to chase the player when:

    1) They are within range of the player (e.g., within 500 pixels)

    2) they are on the same platform as the player

    I can implement 1 with the LOS behavior, but that also makes the enemies follow the player if the player is on other platforms nearby. E.g., when the player walks underneath the enemy's platform and is within 500 pixels of the enemy, the enemy follows the player's movement.

    I've thought of an approach where each platform has an ID, and any enemy on that platform has the same ID, and when the player touches the platform they get that ID, etc, but that will get cumbersome quickly with lots of enemies and platforms. Is there a better way to do this? I'm sure it's been done many times before.

    Thanks

  • because it only tests the UID of the sprite with the lowest IID

    You're absolutely right, that's explains it perfectly. Thanks!

  • Seems like a simple question to answer, but I'm not understanding why my code is doing this...

    The only difference in the code below is:

    - in the 1st, it's comparing Sprite.UID > 1 (true for all 3 Sprites)

    - in the 2nd, it's comparing Sprite.UID > 2 (true for 2 of 3 Sprites)

    I would have thought that if it was true for ANY Sprite, the action block would execute. But it appears that the event 2 condition returns true (subsequently setting the 'result' and 'counter' variables) ONLY when the condition is true for ALL Sprites.

    Can someone clarify why it works this way?

    Thanks

  • because there's only one instance of the function object

    "function object"? As I understand it, functions aren't objects and they don't have instances. Instead, they're events. Per the docs:

    Functions are special kinds of events that can be called from actions. https://www.construct.net/en/make-games/manuals/construct-3/project-primitives/events/functions

    But maybe I'm misunderstanding what you're saying...?

  • Thanks for the reply. I'm trying to understand what exactly are the rules for running functions against a picked set of objects.

    Actions always try to apply to one object. Without a condition, an action has no way to pick an object, so it applies to all objects.

    Per my 2nd post above, I believe the rule is: object-specific actions are run once for each object picked, non-object-specific actions run only once per event (regardless of how many objects are picked).

    But when you add a condition, the action gets some instruction. If the condition could be satisfied by multiple objects, it picks one at random. Adding "for each" forces the actions to repeat for each object that satisfies it.

    So in your top event, the function is only picking one random Sprite uid. If you add a "for each sprite" on that subevent, it should call the function three times.

    Re: "random", I'm guessing C3 doesn't pick objects at random. There are probably some rules it follows for to decide which object UID to pass to the function - e.g., it picks the object with the smallest UID. That's what my code does every time, it picks the Sprite with the smallest UID.