pandabear7413's Recent Forum Activity

  • 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

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

  • Try Construct 3

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

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

pandabear7413's avatar

pandabear7413

Member since 9 May, 2021

None one is following pandabear7413 yet!

Trophy Case

  • 3-Year Club
  • Jupiter Mission Supports Gordon's mission to Jupiter
  • Forum Contributor Made 100 posts in the forums
  • Regular Visitor Visited Construct.net 7 days in a row
  • Steady Visitor Visited Construct.net 30 days in a row
  • RTFM Read the fabulous manual
  • x4
    Quick Draw First 5 people to up-vote a new Construct 3 release
  • Email Verified

Progress

10/44
How to earn trophies