Sine + Z Index not working as expected... Help??

0 favourites
  • 4 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hi!

    I've been working on setting up a Player object with multiple parts for a friend's project. I created a Player object in which the arms are separate from the player, and therefore can move independently of the Player. However, I ran into two huge issues that I cannot seem to fix. I am honestly frustrated.

    You can check out the CAPX here.

    ( drive.google.com/open )

    The First Issue

    As you can see in the CAPX, I set the Sine Magnitude and Period to be exactly the same for each arm object, except one is negative and one is positive; depending on the side. However, for some strange reason every Player sprite created at any point farther along the X-Axis than the first created Player sprite, has the arms swing wildly despite the debugger showing them as having the same magnitude, period, and sine values. And I know it has to do with the X-Axis because I ran it the same with all of the objects having the same player number and it only triggers if the object it created farther to the right than the first.

    The Second Issue

    For whatever reason, the arm objects refuse to move in-front of or behind the Player sprite for any of the Player Objects that aren't the first one. No matter what, they're either both on top of the sprite or both underneath; and on the rare occasions where I get it to work, mirroring the Player Object messes it up again by moving both the arms behind the Player Object.

    I seriously have no idea why these are happening, or have any idea to fix these. If someone could help me out with this issue, it would be greatly appreciated.

  • 1. "Trigger once" in events 24 and 27 doesn't mean "once per instance". This is a very common mistake people make. I don't like using this condition in sub-events, and especially in loops...

    2. In events 18-28 you loop through Player_Coll and pick their linked Player_Arms, but you don't pick the correct Player_Image instance for each Player_Coll. That's why there is a mess with z-order.

    .

    I suggest you read about containers. Put Player_Coll, Player_Image, Player_RightHand, Player_LeftHand sprites into a container. It will be much easier to manage them, you can create Player_Coll and other objects will be created automatically, just need to position them and pin.

    Same with destroying - just destroy one object and don't care about the rest.

    You will not need PlayerIndex variable, when you pick one object instance from the container, others will be picked automatically in the same event.

    So your event #18 will look like this:

    For each Player_Coll
     If Player_Image is mirrored -> LeftArm move in front, RightArm move behind
     else -> LeftArm move behind, RightArm move in front
    

    Easy!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • dop2000

    1. I removed the trigger once, and now it seems like all of the Player objects have their arms swing rapidly, not just the second and third players. Was that what I was supposed to do?

    2. How would I do that if the Left and Right Arms are the same object? Like when they're created, how would I sort through them and assign one to be the left and one to be the right? Or would it require two different objects to work properly?

    Thanks for helping me out, I appreciate it!

  • 1. It would probably be easier and better for performance to create a function "ChangeDirection", which takes Player_Coll.UID as parameter. In this function you pick Player_Coll by UID, mirror/unmirror the body, update z-order for arms, change Sine magnitude etc.

    Every time a player changes direction, call this function.

    .

    I strongly suggest using a container. Container can only hold one instance of each object (one collision box, one body, one head etc.). So you can't put two arms in it. You'll have to make two identical sprites - LeftArm and RightArm. But this is a small price to pay for all the benefits you'll get.

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