I need help related to functions and instances

0 favourites
  • 8 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I was making a game that has a complex animation system and everything was going well, until I implemented a second player character.

    My system works like this:

    I only place the character's hitbox on the layout and at the start of the layout, the event sheet places all the body parts onto it.

    Then, every tick, the position and angle of the body parts is updated. I don't use pins because the pins started lagging really badly once I daisy-chained more than one part.

    Because I wanted my game to be dynamic and scalable, I used functions to implement the placing and the updating of each character's parts.

    I have those 2 functions (stemming from one Function object, does that make a difference?), createCharacter and assembleCharacter, which are called with either 0 or 1 as their parameter, depending on which player they should affect.

    The way that works is as follows:

    The hitbox has an instance variable playerNumber that corresponds to the instance variables owner in the body parts.

    For some reason, assembleCharacter places the pelvis (and thus subsequent parts) on the last called hitbox, even though I tell it to discriminate based on playerNumber and owner.

    Here is the file:

    https://www.dropbox.com/s/d5vf9ltlkstqrte/mortifyingProblem.capx?dl=0

    I've removed almost everything that is not related to the problem. There may still be some residual behaviors and instance variables that shouldn't affect anything though.

    I've also set the event sheet up so it is observable what is happening. In the first 4 seconds, the assembleCharacter function is alternately called with 0 and 1 as its parameter each second, after that both are called every tick.

    I've been working on fixing this for close to 24 hours. I would be very thankful for any help.

    Edit: I think I have enough reputation to post the file now.

  • Sorry for the bump, but I now have enough reputation to post the link to the file. See the post above.

    Thank you in advance.

  • your functions seems well defined.

    Actually, I don't understand what you want to do. How should be the character? how should it move?

  • In the file I provided, for demonstration purposes, it only places two pelvises (one for each character) rather than all of the body parts.

    The problem is that the function assembleCharacter for some reason takes all the instances of pelvis and places them on one hitbox, rather than just taking the one specified through the parameter and placing it on the corresponding hitbox.

  • and what is the grey square in the middle?

    I think you should add a variable to differentiate all the instances of pelvis, then you could use this variable in the function to place them at different positions.

    An other way to do what you want is the "pin" behavior, which is designed exactly for these situations, I don't know why your pins was lagging.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • In event 9, when you pick the correct pelvis and set it's position you need to refer to either the object or the family in both the condition and action. You can't mix them.

    You can have pick pelvis -> set pelvis position or pick character -> set character position but you can't have pick character -> set pelvis position. In that case you're setting the position of all pelvis objects not just the ones picked by the family condition.

  • Thank you, ramones. I was tinkering around just minutes ago and found that it worked if I used the direct object type.

    You confirmed it, though.

  • You might also want to look at containers:

    https://www.scirra.com/manual/150/containers

    If used correctly this will make referencing the objects that should reference eachother much easier..

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