GML Q: Tenticle

Z

zendraw

Guest
Hi,

can some1 help me out with some guidelines or code on how to make tenticles? like as if one instance is attached to another.

i really have no idea how to approach this.
 
E

Ephemeral

Guest
You could probably manage something rudimentary with a series of segment instances where each updates its origin to where the previous segment is pointing using lengthdir_x() and lengthdir_y(), or something unwieldy by using Weld Joints?
 
Z

zendraw

Guest
give me an example, im not sure what you mean by updatin its origin?
 
E

Ephemeral

Guest
Well, you make a segment in the sprite editor, pointing from left to right, and then you put its origin at Left Middle.

You make an object, give it the sprite, and then make a second object to control it.
In the second object, you do something like this:
Code:
/// Create Event

tentacle_length = 8;
segment_size = sprite_get_width(spr_segment);

var tx = x;
var ty = y;
var segment_direction = direction;
for (var segment = 0; segment < tentacle_length; segment += 1;)
{
    tentacle[segment] = instance_create_layer(tx, ty, layer, obj_segment);
    tentacle[segment].image_angle = segment_direction;
    tentacle[segment].direction = segment_direction;
    tx += lengthdir_x(segment_size, segment_direction);
    ty += lengthdir_y(segment_size, segment_direction);
    segment_direction += irandom_range(-20, 20);
}
This will generate the tentacle, and then you have a pair of for loops in the step event, one to handle controlling its behavior by rotation and a second to conversely update the position of each segment.
 
Z

zendraw

Guest
can this idea apply in GM1? i see you use an unknow function for me instance create layer.
 
E

Ephemeral

Guest
So? Use instance_create() instead... That cannot possibly be difficult to guess.
 
Top