1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GML Q: Tenticle

Discussion in 'Programming' started by zendraw, Apr 1, 2017.

  1. zendraw

    zendraw Member

    Joined:
    Jun 20, 2016
    Posts:
    1,385
    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.
     
  2. Ephemeral

    Ephemeral Member

    Joined:
    Mar 1, 2017
    Posts:
    185
    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?
     
  3. zendraw

    zendraw Member

    Joined:
    Jun 20, 2016
    Posts:
    1,385
    give me an example, im not sure what you mean by updatin its origin?
     
  4. Ephemeral

    Ephemeral Member

    Joined:
    Mar 1, 2017
    Posts:
    185
    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.
     
  5. zendraw

    zendraw Member

    Joined:
    Jun 20, 2016
    Posts:
    1,385
    can this idea apply in GM1? i see you use an unknow function for me instance create layer.
     
  6. Ephemeral

    Ephemeral Member

    Joined:
    Mar 1, 2017
    Posts:
    185
    So? Use instance_create() instead... That cannot possibly be difficult to guess.
     

Share This Page