GameMaker mp_potential_step_object (with multiple objects)

M

mtski

Guest
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 :)
 

CloseRange

Member
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
 
M

mtski

Guest
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.
 

Evanski

Raccoon Lord
Forum Staff
Moderator
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
mp_potential_step_object as I have no "Solid" objects in my game.
mp_potential_step works better by checking solid objects to avoid

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.
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
 
M

mtski

Guest
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.
 

CloseRange

Member
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:
M

mtski

Guest
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
 

Evanski

Raccoon Lord
Forum Staff
Moderator
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.
Thats a myth, that source of information is invalid
 

Bentley

Member
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
 

CloseRange

Member
@Bently might be right:
An instance can be flagged as solid through the object properties, or by changing the value of this variable. If solid is true, a special collision event is generated whereby the instance is returned automatically to the position it was at in the step previous to the collision. If it is set to false, all collisions must be dealt with through the collision event.
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
 
C

cirin92

Guest
@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?
 
M

mtski

Guest
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 :)
 
M

mtski

Guest
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!
 

FrostyCat

Redemption Seeker
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;
  }
}
 
M

mtski

Guest
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;
  }
}
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?
 

GMWolf

aka fel666
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...
 
M

mtski

Guest
Yay, ok :)
I'm still honing my coding skills and ability to think through code :)

Thank you
 
Top