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

Another pathing problem

Discussion in 'Programming' started by Patrik Grinsvall, Dec 1, 2018.

Tags:
  1. Patrik Grinsvall

    Patrik Grinsvall Member

    Joined:
    Feb 15, 2017
    Posts:
    12
    Since i solved my orignial question which was creating a new path in each step event (dont know why it only affected a few enemies, but sitll good).

    I go directly to the :
    *BONUS QUESTION*
    The manual says about mp_grid_path
    Code:
    mp_grid_path(id, path, xstart, ystart, xgoal, ygoal, allowdiag);
    x start Starting x coordinate of the new path
    y start Starting y coordinate of the new path
    xgoal Finishing x coordinate of the new path
    ygoal Finishing y coordinate of the new path
    
    However i have always used absolute coordinates and not coordinates divided by cell size. Anyone know the answer to this? It would be really buggy if the xgoal and ygoal was coordinates and not pixels.

    Any ideas?




    I spawn 5 enemies at x = 0. Their y are random. They all use pathing and here is the relevant code:

    Spawning code:
    Code:
    // if it is time to spawn the enemies.
    if(time == spawn_time && enemies_alive == 0) {
     
        // spawn enemies
        for(tmpx = 0; tmpx <= spawn_amount; tmpx++) {
            var randomy = irandom_range(0, window_get_height());
            randomy = irandom_range(0, window_get_height());
            var tmpinstance = instance_create_depth(1, randomy, 100, o_enemy1);
        }
    
        // increase difficulty...
        level++;
        spawn_amount = spawn_amount + level;
        enemy1_hp = enemy1_hp + (level * 2);
        enemy1_speed = enemy1_speed + (level / 10)
        enemy1_attack_damage = 10 + (level*2);
    }
    
    Code that creates the path (create of enemy1):

    Code:
    if(instance_exists(nearestInstance)) {
        myPath = path_add();
        mp_grid_path(global.grid, myPath, x, y, nearestInstance.x, nearestInstance.y, true);
        path_start(myPath,2, path_action_stop, true);
        show_debug_message("we  have a path!");
    } else {
        show_debug_message("we dont dont 1! have a path!");
    }
    
    Now to the problem. Only some of the enemies move. All have their path layed out but they just refuse to move...
    See attached screenshot. The red tiles are impassable tiles. The lines are the paths and i have marked what objects are moving and what is not. I have also tried to set a fixed speed to 2 and a bunch of other things even removing all obstacles from the game. Still same result.
     

    Attached Files:

    Last edited: Dec 1, 2018

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