GMS 2 mp_potential_step_object (with multiple objects)

Discussion in 'Programming' started by mtski, Aug 15, 2019.

Tags:
  1. mtski

    mtski Member

    Joined:
    Apr 18, 2019
    Posts:
    26
    Hi all,

    Just a quick question hopefully. I have been working on my pathfinding system and so far everything seems to be mostly working. Sometimes my "units" are unable to find a path within the mp_grid I have setup and so I have them using mp_potential_step_object as I have no "Solid" objects in my game.

    Is there a way to expand upon this to include different objects aside from using parenting? Reason being is I already have parent objects but I would like them to stay different from one another aside from issuing another grander parent if that makes sense. Here is my code so far on this:

    Code:
    path = path_add()
    pathing = mp_grid_path(global.mpGrid,path,x,y,destinationTargetx,destinationTargety,1)
    
    if pathing == 1 {
        path_start(path,spd,path_action_stop,0)
    }
    else {
        mp_potential_step_object(destinationTargetx,destinationTargety,spd,obj_stickPile) //new path
    }
    Thanks for looking :)
     
  2. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    735
    I'm a bit confused why you chose to use mp_potential_step_object.....
    why not just use mp_potential_step?
    if im not mistaken that's what you want
     
  3. mtski

    mtski Member

    Joined:
    Apr 18, 2019
    Posts:
    26
    Hi CloseRange,

    I thought mp_potential_step was for use of the "check all" function which requires objects be marked as "Solid". Am I missing something? I admit I do not fully understand the differences between these options.
     
  4. EvanSki

    EvanSki King of Raccoons

    Joined:
    Apr 17, 2018
    Posts:
    533
    mp_potential_step works better by checking solid objects to avoid

    Check all, means check all instances or just the solid ones

    so it would avoid all instances to get to its target
    or just avoid the solid ones
     
  5. mtski

    mtski Member

    Joined:
    Apr 18, 2019
    Posts:
    26
    This may be a myth, but I had read somewhere that the use of marking objects as "Solid" implies you are using GMLS physics engine(which I am not) and that it can cause some other issues down the road with certain things. Is any part of this true?

    Otherwise, I will definitely just use the "solid" options for my pathfinding system.
     
  6. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    735
    yup that was my mistake I'm not use to mp functions.
    Your best bet is to create a dummy object called something like obj_path_avoid
    set its' image to just a black square that's the size of your objects (the object can be set to be invisible)
    set the mp potential to avoid only this object
    go into the objects you want to be avoided and do:
    Code:
    instance_create(x, y, obj_path_avoid);
    
    EDIT: yes that's kind of a myth kinda sorta maybe.
    I think gm always has physics but by default the values are just put to 0 unless you have physics enabled. having a solid object won't set it on but in general the solid option shouldn't be used unless its for physics or wacky functions like mp_potential_step

    ANOTHER EDIT:
    I would personally turn it into a script but I'm weird so here you go:
    Code:
    /// avoidMePlz(targx, targy, stepsize, obj1, obj2, obj3, ...);
    var tx = argument[0];
    var ty = argument[1];
    var stepSize = argument[2];
    
    for(var i=3; i<argument_count; i++) {
        with(argument[i]) {
            instance_create(x, y, obj_path_avoid);
        }
    }
    mp_potential_step_object(tx, ty, stepSize, obj_path_avoid);
    instance_destroy(obj_path_avoid);
    and to call it:
    Code:
    avoidMePlz(destinationTargetx, destinationTargety, spd, obj_stickPile, obj_anotherThing, obj_wowAThing);
    but sadly this being a script it's limited to 16 arguments or in this case only 13 objects at once :(
     
    Last edited: Aug 15, 2019
  7. mtski

    mtski Member

    Joined:
    Apr 18, 2019
    Posts:
    26
    Wow, thank you for the code and feedback. I've been working on and learning pathfinding for the past 3 weeks effectively halting my progress. I do believe I am coming close to finishing though as things generally are working better since my discovery of a* star algorithm and the us of mp_grid functions.

    Its very unlikely I would need anymore than 16 arguments anyways. I will study your code and see what happens later tonight after I get off work.

    Thanks again
     
  8. EvanSki

    EvanSki King of Raccoons

    Joined:
    Apr 17, 2018
    Posts:
    533
    Thats a myth, that source of information is invalid
     
    Bentley and Kezarus like this.
  9. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    765
    I could be totally wrong, but I think solid is something like this:
    Code:
    // Backtrack
    x = xprevious;
    y = yprevious;
    
    // Move to the solid you collided with
    move_contact_solid(direction, something); 
    Check the manual though
     
  10. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    735
    @Bently might be right:
    but based on the description i'd be inclined to say that it doesn't actually include the move_contact_solid
    but this means it definitely doesn't turn on any physics
     
  11. cirin92

    cirin92 Member

    Joined:
    Aug 15, 2019
    Posts:
    4
    @CloseRange Could you tell me where you put all of this code? I think that "instance_create" should be placed in Create Event, but what with rest of your code? Is it Step event?
     
  12. mtski

    mtski Member

    Joined:
    Apr 18, 2019
    Posts:
    26
    It is in the step event, being run through a script while the unit is moving only. I do like the "obj_avoid" idea though and plan on putting that into my code tomorrow to see how it works. I'm still learning pathfinding and coding in general, but I've got a good handle on logic, so I can usually figure out issues as I go. Pathfinding has been my challenge last few weeks though. Any other ideas on logic is welcomed :)
     
  13. mtski

    mtski Member

    Joined:
    Apr 18, 2019
    Posts:
    26
    looks like the "pathavoider" idea worked! Thank you so much for everyones help on this. As always, I will still accept any other ideas in regards to path finding if anyone else wants to contribute. Thanks all!
     
  14. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,320
    If you do not already use solid, a lighter alternative to blocker objects is solid tagging. The idea is to temporarily set the solid property and take advantage of the various built-in functions that care about solids.

    As an example, here is an adapted version of CloseRange's solution:
    Code:
    /// avoidMePlz(targx, targy, stepsize, obj1, obj2, obj3, ...);
    var tx = argument[0];
    var ty = argument[1];
    var stepSize = argument[2];
    for(var i = 3; i < argument_count; i++) {
      with(argument[i]) {
        solid = true;
      }
    }
    mp_potential_step(tx, ty, stepSize, false);
    for(var i = 3; i < argument_count; i++) {
      with(argument[i]) {
        solid = false;
      }
    }
    
     
  15. mtski

    mtski Member

    Joined:
    Apr 18, 2019
    Posts:
    26
    Im trying to figure out what your code does without applying it. Is it that you are turning solid on and then switching it off right away after the path has been checked?
     
  16. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,360
    That's an interesting problem:
    Aside from frostys nightmarish solid system, there doesn't seem to be a good way to pass collections of objects to GM.

    Parenting does work but not for every situation.

    I think another possibility would be to temporarily change the type of a bunch of objects and then change them back.
    But that's far worst still than the solid solution...
     
  17. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,320
    That's exactly what I'm doing.
     
  18. mtski

    mtski Member

    Joined:
    Apr 18, 2019
    Posts:
    26
    Yay, ok :)
    I'm still honing my coding skills and ability to think through code :)

    Thank you
     

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