How do I differentiate between two instances of the same object?

Not favoritedFavorited Favorited 0 favourites
  • 8 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hi, newbie here. I've searched the forums, tutorials, and FAQs, and tinkered with all kinds of different events and configurations, but I can't seem to find a fix for my problem that I understand.

    I'm making a platformer where the player can pick up and throw blocks. This works great if I only have one block on the screen, but it doesn't work for two blocks. When two blocks (2 separate instances of the same object) are spawned, and the second block is picked up, the "throw" action only affects the first block that was created regardless of the distance from the player, leaving the player holding the second block without being able to throw it.

    Any help would be much appreciated! Thanks!

  • You need to pick the block that was picked up. At the moment the throw logic on 2nd event applies to all blocks so a condition is needed on the left to pick that one block. I would use an instance variable on the block so set a value on the one you are throwing in the 1st event, so you can pick it in the second event. You could use 'is pinned' but I prefer a variable like 'isHeld=yes'

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Perfect, thank you!

    Here's what I ended up going with, for anyone else following:

  • You should put the foreach condition at the bottom of the event block. At the moment construct will pick all blocks then evaluate them, rather than only looping over blocks whos conditions return true.

    You way will still work correctly, but if you have lots of blocks it wont be as efficient.

  • You should put the foreach condition at the bottom of the event block. At the moment construct will pick all blocks then evaluate them, rather than only looping over blocks whos conditions return true.

    You way will still work correctly, but if you have lots of blocks it wont be as efficient.

    I gave that a shot, but it ended up grabbing all the blocks in the stage, then catapulted them out of the player at all angles. Not the desired effect, but it did look cool!

  • A "For Each" loop will not work properly below a compare condition... unless the compare condition for the distance is replaced with "Pick by comparison" in the system condition.

  • I kept my response above simple and related to picking only so as to not confuse. But yeah the usual for a platformer I think would be an overlap check, player is overlapping block, and if they can overlap multiple you can use this with 'pick nearest block to player', rather than a for each with system condition comparing distance which won't work well.

  • The event configuration in the screenshot I posted above works pretty well. I'm considering this problem solved, so thank you all for your help! Here's an example of what I was trying to accomplish, if anyone is interested. Note that I only have gamepad controls for picking up/throwing at the moment. I'll try to incorporate the keyboard in the future.

    construct.net/en/free-online-games/block-example-87657/play

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