pandabear7413's Forum Posts

  • 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?

  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • Let me take a stab at answering my own question: It's because calling the "move" function is not an object-specific action. Only object-specific actions (e.g., Sprite set animation) are called once per picked object. Actions that are not object-specific are only called once per event, regardless of how many objects are picked.

    Is this accurate?

  • Here’s my code. I have 3 Sprite objects, and all have state set to “good”. When I press the right arrow, “count” is set to 3 (i.e., 3 sprites are picked), but the “move” function is only called once with the UID of the first sprite create, so only that sprite moves.

    Can someone please explain to me why this code only calls the "move" function once, and not once for each object picked? Per the C3 docs: Another way to think about an event is "If all conditions are met then run actions on the instances meeting the conditions". https://www.construct.net/en/make-games/manuals/construct-3/project-primitives/events/how-events-work

    I understand that adding a ‘for each Sprite’ condition before calling “move” will get all sprites to move, but I’m trying to understand why this is necessary.

    Thanks

  • dop2000 I get so pumped when I see you're responding to one of my questions, you are always spot on with your answers! This is exactly what I was looking for, and that tutorial from Ashley is gold. Thanks again!