How do I made a stretchy "neck" out of body segments?

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

    I'm trying to make something kind of like those old SNES games where basically, you have an enemy with a "stretchy neck" with the neck made out of balls or something, kind of like what's in this Ckickteam tutorial:

    youtube.com/watch

    I took a stab at it, but I couldn't manage to pull it off properly. The neck isn't moving the way I would like it to (It's moving AWAY from the body), and it's too far away from the body, not connecting with it.

    Here's my code, I'll share the project file if you need me to

    Can somebody please point me in the right direction? I'd appreciate any help I can get. Thanks

    Tagged:

  • dropbox.com/s/48rdqokyr566kmd/stretchyneckexample.c3p

    Constructsaur goes rawr.

    Note that you can calculate the difference in x and difference in y from the head to the body and store it in an instance variable like in the tutorial if you want to, but I just put it directly in the expression.

    Edit: Also added a second event sheet, doing the exact same thing with the lerp expression, which is how I would probably approach this. The way on event sheet 1 is more like how the tutorial does it though. The end result is exactly the same either way.

  • Woah, this is great, thanks for making such a simple to understand example!

    However, I have a few more hurdles I want to clear if that's alright...

    1. Let's say I have multiple enemies who have this stretchy neck. If there are more than once instance of each thing in the example...

    Then all of the necks just connect to the first instance of the body and head, instead of both of them getting their necks

    2. If I want to spawn multiple instances of this stretchy neck thing, do I need to insert the head and necks for each individual enemy? Isn't there a way to just place the body in the editor, then in the game it automatically spawns in the heads and necks? Can this be done with containers?

    (You can see in my original code in the top comment that I tried to spawn a neck and head for each body)

    I'm going to experiment with the example to see if I can pull them off, but help would be greatly appreciated.

    Thank you again for sharing the CAPX!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You'll need to identify and associate the sets of parts. A simple solution would be to assign a common instance variable to each set, so that you can use it to pick the relevant parts in your events.

    You can absolutely spawn parts at runtime. Just on start of layouts or whenever, for each body, spawn parts. Containers I think would not be as suitable since you need multiple instances of just one part. Hierarchies might be more applicable, but I'm not familiar with them.

  • Alrighty, I went and edited the example

    When the layout loads, both heads and all necks spawn (However, all the necks are connecting to one single body still)

    Unfortunately, whenever I try to spawn a body in during the preview, no additional necks or heads appear, just the body.

    The culprit is that Trigger Once condition. But once I remove it, heads spawn endlessly. I'm trying to tell it Trigger Once for each body, but it only triggers once for each body at runtime, not at all times. Is there a way to fix this?

    Also,

    I've added this ID instance variable to the head, body, and neck. Do I have to manually add this number to every body and set the body's value to the head and neck when they spawn? And if so, how will I do this for spawning bodies in during the preview like mentioned earlier? Do I need to use IID or UID instead, and if so, how?

    Thanks in advance

  • I tried this a bit, and there are a few things that make it significantly more complicated. For starters, you can't use the object.count expression anymore, because that will get you the total count of all necks. object.pickedcount doesn't work either since we're running a loop per neck so there's only 1 neck picked at any given time. We also won't be able to use object.IID to keep our necks in order either, since set 1 will have IIDs from 0-5 and set 2 will have IIDs from 6-10 for example (it's not 0-5 for each one). I'll see if I can think of a more flexible solution later today.

    Edit: Dynamically creating a set at runtime should be easier, it's just a matter of setting all the right variables and creating the associated parts whenever you create the body. However, you'll need to know all the data you need for the neck part to work properly first. It's best to work on one thing at a time.

  • You're right, we should focus on getting the necks to work individually first.

    So, here's the code I still have. The entire code for checking if a body exists, then spawning necks and heads for each body:

    I tried several things here, including IID, as shown in the image. I also tried UID, but when debugging, all the ids for the necks and head are zero, which doesn't feel right. If the IID of the second body is 1 and I add that value to the neck ID, should the neck's ID variable be 1, or am I missing something?

    Second, I tried applying the body's ID instance variable to the necks and head instead. When debugging, this DOES indeed change the values of the necks to 0 and 1 respectively, but all necks still attach to the one body regardless...

  • Updated the example. You can create them dynamically, and each neck and head should be associated with it's body via the body's UID.

  • Thank you so very kindly, I understand how it works now.

    I really appreciate you going out of your way to create this CAPX, I can apply this to other parts of the game now.

    Thank you so much ^.^

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