0 Favourites

Controlling and picking between instances of object

  • Hi, I have a couple of problems I need help with.

    1) I'm making a game where I have multiple (let's say 3) instances of an object and have those objects be affected by individual hitboxes for each. All objects need to be able to be affected separately by Player hitting the hitboxes, but I also need an event that activates only when all three objects are at their correct values (defined by different instance variable value set for each object). Basically, when player hits the hitbox for an object it's value will increase by one and only when ALL 3 of the objects are set at their respective correct values, an event will activate.

    I've defined instance variables to the hitboxes and objects so that when they match, the hitbox affects the object with same number, and that works just as planned. But how do I make the game check that all three instance variables (with different values each) are right before activating the next event? Right now, my events activate if only one of the objects is at the correct value. What is the simplest and best solution to fix this?

    2) I have enemies you can jump on (original, I know) and they will get estroyed. At start of layout I spawn hitboxes for each enemy and when player collides with it (and platform is falling), the enemy and hitbox will get destroyed. All well and good and working right, until I have two enemies next to each other and player hits both enemies on landing. In that case I'd want both of them to get destroyed, but what happens is the player dies instead (like they are touching the enemy and not the hitbox). If I disable the "platform is falling" event then when colliding both enemy hitboxes get destroyed but it only destroys one of the enemies. I suspect others have had similar problems before and there is an elegant solution to solve this situation, any advice?

    3) I have multiple doors in the layout. When player enters door 1 he spawns to door 2 coordinates in the layout. When he goes through door 2 he gets back to door 1 coordinates. But what if there are more doors in the layout, let's say also doors 3 and 4 which lead to one another. Doors have individual instance numbers each but I'm having trouble comparing and picking automatically the coordinates of the target door to go to. What's the most effictive way to make this kind of system without unneeded clutter in events, tedious setting of coordinates by hand for each level or cloning objects?

    Thanks a lot for any help, it is much appreciated!!

  • 1. Id use multiple objects rather than instances. Instances don't work well with multiple collisions, or containers.

    2. You could do a function that checks both the x, and y of enemies in a set range of the on collision event. That breaks picking from the collision.

    3. If its in order, use a counter variable. On collision with door player add 1 to counter, player go to door(counter). If not then its the long way.

  • Waltuo more ideas...

    1) add a second instance variable to the objects called Complete or Unlocked, and when the hit box number and object number match, set the Complete flag to True. Then you can add an event to see how many objects are unlocked, if that matches the number of objects, then execute the next events... (first have an event to pick objects with Complete True, then you can have a subevent check the Picked.Count to see if it matches the desired number.)

    2) you probably need a "For Each" enemy in the code that destroys them. It is probably only killing one, which leaves the second one there to kill you.

    3) add an instance variable to the doors that specifies the target door to jump to. I would put the UID (Unique ID) of the target door in that variable. Then you can pick the target door by UID, and set the player to that door's coordinates. (You may have to add a Pick All doors, before you can pick the target door).

    another way- which may be easier to set up in advance if you don't know the UID, is to add another instance variable called DoorNumber, then put the number to jump to in the TargetDoor variable, and pick accordingly... (so the first door would be DoorNumber 1, it's TargetDoor would be 2, etc...)

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Thanks a lot for the help, it's much appreciated!

    I will try your suggestions and hopefully get the issues sorted out. Thanks again!

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