# How to make moving tentacles?

#### Mick

##### Member
Hi! We started making a boss that should have about four tentacles attached to his back. They would move and wiggle randomly and sometimes sweep across the floor. How would one go about and make such a thing the best way? We are not using physics for anything yet but if it's the way to go then we could use physics. Spine is another option but we don't have a license for that. Greatful for help if somebody have found a solid way of doing this!

By the way, it can look old school like classic games with connected circular sprites.

#### GMWolf

##### aka fel666
thats is a super braod question...
the best way? it depends on what exact effect you are looking for?
you could use bones, parent each section to each other... you could use a curve and draw along that.
there are simply too many ways to do it.
and for each of those ways, there are many, many implementations! each with pros and cons.

Try something out. event if it doesnt work! just throw toghether whatever you can. show us, and then we can start helping you!

#### Mick

##### Member
I know it's a broad question, I'm just looking to get ideas. I just started experimenting with bezier curves, I'll see how that turns out.

#### chance

##### predictably random
Forum Staff
Moderator
Parametric curves like Bezier will work fine. Even GM's built-in path functions will work. Updating the control points and re-drawing the path each step is fairly slow, but it's OK for starters.

Do you want the tentacles to interact with other objects? If so, box2D physics works well for that. I've made some interacting tentacles by laying jointed fixtures along the curve path. That seems to work well.

C

#### CaffeineJunky

##### Guest
One way to do it is like they did in some of the older SNES games, and have a series of circles act as the tentacle.

For the moment, you need to envision the joints (the parts of the tentacle that are free to move) in terms of their arm moving plus and offsets in the perpendicular direction for the joints along that arm.

#### Mick

##### Member
Parametric curves like Bezier will work fine. Even GM's built-in path functions will work. Updating the control points and re-drawing the path each step is fairly slow, but it's OK for starters.
I'm testing with a bezier curve script now, having one gm path controlling the end point and one path controlling the "curve".

Do you want the tentacles to interact with other objects?
That's not really necessary, normal collisions are fine I guess. I will look into jointed fixtures if I need to later but I think I can manage without them.

One way to do it is like they did in some of the older SNES games, and have a series of circles act as the tentacle.
That's exactly what I started doing, having good progress so far.

Thanks for the ideas!

#### Nocturne

##### Friendly Tyrant
Forum Staff
I made some tentacles for Skein:

How I made them was to make a path with three points on it, and then make the path smooth and then set am x/y goto position for the top of the tentacle (point 3). I then lerp the end of tentacle to that point and repeat, and I also do the same for point 2 but to a lesser degree.

#### Nocturne

##### Friendly Tyrant
Forum Staff
@FrostyCat: Thanks for that, but... Maths is NOT my strong point and I don't have least idea how to even start applying those formulas to a game. Which is why I used paths. It's easy as they already have a smooth function, I already know how to use them, and I can easily draw stuff along them to create the tentacle effect. This is why I love GameMaker...

#### TheouAegis

##### Member
I didn't look at the code he went off of, but I'd guess it's just a matter of redefining P1, P2, and P3 whilst leaving P0 (the anchor) intact.

#### Mick

##### Member
Hey, that looks awesome! But may I ask how you made them move randomly
They are not actually moving randomly, I'm using the bezier script and x1,y1 are moving along one path and x2,y2 (the end of the tentacles) are moving along another path. I created paths for the tentacles in the path editor.

(The end of the tentacles are separate objects that move along their paths and the tentacle object uses x,y from those objects for the bezier script)

#### TheouAegis

##### Member
You should take it up to the next order and implement 2 endpoints so you have more flailing.

#### Mick

##### Member
EDIT: But you know, the object that the tentacles follow CAN move by itself, like an AI. Just make it where instead of following a path, do some code in the object, saying that it wriggles around aimlessly and randomly! This would look nicer, and save space for your game...
I did that first but I got smoother movement using curved paths, I'm sure it can be made to look nicer still, but I'm the only programmer in my team and have a lot still to do. The tentacles will also attack the player (dive down and grab the player), the path movement will then pause and instead the end point will lerp towards the player.

#### Tronco

##### Member
Sorry for necroposting, i'm really interested in this kind of effect, trying to reproduce the tail behaviour of R-Type's first boss.

Could you please post some example code of one of the methods used to get this effect?
The bezier curve script links are dead and i don't really have any clue on how to start coding something like that (very little experience in math i'm sorry )

The only main difference (maybe it's a big one) is that in my case the sprites for the joints are not spherical, they are rectangular, so i need to take the image_angle factor in count to make them look "joined" togheter i think.

Thanks

#### Mick

##### Member
You can use the path system in GMS to accomplish this. I created a simple example (using GMS1.4) that uses one path and moves the end position according to the mouse. To make it look better you also need to move the other points in the path.