GMS 2 (SOLVED) Trouble with lengthdir _x _y in a grid.

Discussion in 'Programming' started by MagnumVulcanos, Feb 17, 2019.

Tags:
  1. MagnumVulcanos

    MagnumVulcanos Member

    Joined:
    Dec 20, 2016
    Posts:
    46
    Code:
    for (var w = 0; w < ds_grid_width(grid_slots); w++ ) {
        for (var h = 0; h < ds_grid_height(grid_slots); h++ ) {
    
            var xx = place_cubicle.x +
            lengthdir_x( w*tile_size, place_cubicle.image_angle );
            var yy = place_cubicle.y +
            lengthdir_y( h*tile_size , place_cubicle.image_angle -90);
            
            var inst = instance_create_layer( xx, yy,
            "l_inst_appliances", obj_temp_cubicle_tile );
        }
    }
    
    Untitled.png

    I am having lots of trouble with lengthdir, I am trying to create instances in a grid, and I am getting the desired result only when image angle is 0, whenever image angle is greater or smaller, the grid tiles get closer to each other, but do not rotate relative to the object's origin...
    I do not know why this happens, any ideas?
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,572
    I don't actually understand your question or problem, but I can tell you that looking at your code these two lines are likely not correct:

    Code:
    
           var xx = place_cubicle.x + lengthdir_x( w*tile_size, place_cubicle.image_angle );
           var yy = place_cubicle.y + lengthdir_y( h*tile_size , place_cubicle.image_angle -90);
    
    
    The problem is that they use different length and angels. There's basically no circumstance where you would want to do that. The lengthdir function basically calculates the non-hypotenuse sides of a right triangle given the length and angle of the hypotenuse. If you give lengthdir x/y different arguments you're basically telling them to calculate the sides of different triangles.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice