Legacy GM Object movement with paths

S

shostifrosty

Guest
Hello everyone!

I've been struggling for several days with the objects movement through paths, and it would be awesome if someone could help me out a little with an issue I have.

What I want to do is to have pedestrians moving around in paths I specifically designed for them. So far, I could make them follow a path and face the right direction.

path problems.JPG

However I would like them to do more stuff than just eternally following one path (so the thing look more realistic and alive).

In the code above I wanted, for example, a pedestrian to follow the path, complete it, and then stop and change the animation to idle, but it just doesn't work. When the object finishes the path, the animation get stuck and stop running.

Could anyone tell me what's wrong?

Also I was thinking that maybe what I want to do can be done with something better than paths. In that case, what that could be? I'm quite newbie in all of this and I'm struggling great deal.
 
Last edited by a moderator:
S

shostifrosty

Guest
Yeah I meant that! Thanks for suggestion. Anyway there must be something else, because I corrected it, but it still keeps showing the wrong animation.
 

jo-thijs

Member
Hello everyone!

I've been struggling for several days with the objects movement through paths, and it would be awesome if someone could help me out a little with an issue I have.

What I want to do is to have pedestrians moving around in paths I specifically designed for them. So far, I could make them follow a path and face the right direction.

View attachment 19208

However I would like them to do more stuff than just eternally following one path (so the thing look more realistic and alive).

In the code above I wanted, for example, a pedestrian to follow the path, complete it, and then stop and change the animation to idle, but it just doesn't work. When the object finishes the path, the animation get stuck and stop running.

Could anyone tell me what's wrong?

Also I was thinking that maybe what I want to do can be done with something better than paths. In that case, what that could be? I'm quite newbie in all of this and I'm struggling great deal.
I'm sorry, but your description doesn't make sense.
You've set the path to restart when it ends, so the object would never finish the path.
As a result, path_position would be 1 for at most a single frame in each cycle of the path
and you wouldn't notice the animation hanging.

Either there are a couple of important lines you're not showing us in the step event
or there is some other code messing with your pedestrian (which I highly doubt)
or your desciption of what happens is just not accurate.

The best advice I can give is to try changing path_action_restart to path_action_stop.
 
S

shostifrosty

Guest
I'm sorry, but your description doesn't make sense.
You've set the path to restart when it ends, so the object would never finish the path.
As a result, path_position would be 1 for at most a single frame in each cycle of the path
and you wouldn't notice the animation hanging.

Either there are a couple of important lines you're not showing us in the step event
or there is some other code messing with your pedestrian (which I highly doubt)
or your desciption of what happens is just not accurate.

The best advice I can give is to try changing path_action_restart to path_action_stop.
Sorry! I changed it so many times that by the time I took the print screen it was showing that.

In fact the path is set in "path_action_stop" and it keeps working wrong. It will just reproduce the sprite "moving" forever even though the path finished and the object is no longer moving.
 
M

Misty

Guest
I tried! Unfortunately it didn't work :( . Thank you very much anyway :)
Set it to a lesser value. Try .9 or .99. If that doesn't work then something is clearly wrong with your animation.

I don't know what drcha means in any language so I don't know what that would indicate. I assume it is some kind of breathing animation loop. If not then you need to set the image speed to zero.
 
S

shostifrosty

Guest
I found a work around! But it is quite crazy I think.

Everything works if I just destroy the object and create a new one in place. This way the new object have different things (other sprite, it takes a break, then another path, etc.) and it just works!


Code:
///dirección al caminar
depth = -y;

if (direction >= 270 or direction <= 0) {
    sprite_index = Ichigo_andando_frente_drcha;
}

if (direction >= 90 and direction <= 180) {
    sprite_index = Ichigo_andando_espalda_izquierda;
}

if (direction >= 181 and direction <= 269) {
    sprite_index = Ichigo_andando_frente_izquierda;
}

if (direction >= 1 and direction <= 89) {
    sprite_index = Ichigo_andando_espalda_drcha;
}

if path_position = 1 {
   
    instance_destroy ();
    instance_create (x,y,obj_npc_path_stops_1);
}
However, I think it is a very crappy way to solve it. Does anyone know another way so I can look into it?
 
M

Misty

Guest
I found a work around! But it is quite crazy I think.

Everything works if I just destroy the object and create a new one in place. This way the new object have different things (other sprite, it takes a break, then another path, etc.) and it just works!


Code:
///dirección al caminar
depth = -y;

if (direction >= 270 or direction <= 0) {
    sprite_index = Ichigo_andando_frente_drcha;
}

if (direction >= 90 and direction <= 180) {
    sprite_index = Ichigo_andando_espalda_izquierda;
}

if (direction >= 181 and direction <= 269) {
    sprite_index = Ichigo_andando_frente_izquierda;
}

if (direction >= 1 and direction <= 89) {
    sprite_index = Ichigo_andando_espalda_drcha;
}

if path_position = 1 {
   
    instance_destroy ();
    instance_create (x,y,obj_npc_path_stops_1);
}
However, I think it is a very crappy way to solve it. Could anyone give me another way for me to explore and look into? :)
I updated my post a few seconds before you ninja'd me.
 

jo-thijs

Member
Sorry! I changed it so many times that by the time I took the print screen it was showing that.

In fact the path is set in "path_action_stop" and it keeps working wrong. It will just reproduce the sprite "moving" forever even though the path finished and the object is no longer moving.
That should not happen based on the code you provided.

Can you post again the complete code you're currently using?

I tried! Unfortunately it didn't work :( . Thank you very much anyway :)
Don't bother with Misty, he's purpousfully trying to be unhelpful.

I found a work around! But it is quite crazy I think.

Everything works if I just destroy the object and create a new one in place. This way the new object have different things (other sprite, it takes a break, then another path, etc.) and it just works!


Code:
///dirección al caminar
depth = -y;

if (direction >= 270 or direction <= 0) {
    sprite_index = Ichigo_andando_frente_drcha;
}

if (direction >= 90 and direction <= 180) {
    sprite_index = Ichigo_andando_espalda_izquierda;
}

if (direction >= 181 and direction <= 269) {
    sprite_index = Ichigo_andando_frente_izquierda;
}

if (direction >= 1 and direction <= 89) {
    sprite_index = Ichigo_andando_espalda_drcha;
}

if path_position = 1 {
   
    instance_destroy ();
    instance_create (x,y,obj_npc_path_stops_1);
}
However, I think it is a very crappy way to solve it. Could anyone give me another way for me to explore and look into? :)
Yeah, that's indeed not an ideal solution.
 
S

shostifrosty

Guest
That should not happen based on the code you provided.

Can you post again the complete code you're currently using?


Don't bother with Misty, he's purpousfully trying to be unhelpful.


Yeah, that's indeed not an ideal solution.
Well, right now it is like this

1.JPG

And before that, I tried like this

2.JPG

Neither of both working :S !
 

jo-thijs

Member
Well, right now it is like this

View attachment 19212

And before that, I tried like this

View attachment 19213

Neither of both working :S !
You don't want to use object_set_sprite, you want to use sprite_index:
Code:
sprite_index = Ichigo_frente_drcha;
GameMaker makes a distinction between objects and instances.
Objects are blueprints of how some individual in the room should behave (what you program).
Instances are the individuals you create and they are of a certain object type / kind (what you create using instance_create).

When you use object_set_sprite, you change the default sprite for an object during a single run of your program.
This means that if you create instances of that object afterwards, they'll have that sprite.

When you use sprite_index, you change the sprite of the executing instance.
 
M

Misty

Guest
Don't bother with Misty, he's purpousfully trying to be unhelpful.
Go away.

Neither of both working :S !
Look, none of that code is any of what I suggested.

Your code should be this

if path_position>.99
{
image_speed=0
sprite_index=idle_sprite
}

When you use sprite_index, you change the sprite of the executing instance.
Thats nice but her original code already has sprite_index and her first post is outdated code.
 
S

shostifrosty

Guest
It almost worked!! I tried both, jo-thijs, and Misty's :D :D

In jo-thisj's, the sprite EVENTUALLY changed! However, it only shows the first sprite instead of the whole animation.

I tried yours too Misty's, but it seems like the "0.99" didn't work after all. I tried "1" instead, and then it worked exactly as jo-thisj's. It changes the sprite but it won't run the animation.
 

jo-thijs

Member
Look, none of that code is any of what I suggested.

Your code should be this

if path_position>.99
{
image_speed=0
sprite_index=idle_sprite
}

Thats nice but her original code already has sprite_index and her first post is outdated code.
Oh ok, my bad.
I tough you were saying something different.
"set it to .999999 or .99 or .9" is not clear as to what "it" refers to
and sounds more like you were saying to try "if path_position = 0.999999".
However, precision is not the issue here.

It almost worked!! I tried both, jo-thijs, and Misty's :D :D

In jo-thisj's, the sprite EVENTUALLY changed! However, it only shows the first sprite instead of the whole animation.

I tried yours too Misty's, but it seems like the "0.99" didn't work after all. I tried "1" instead, and then it worked exactly as jo-thisj's. It changes the sprite but it won't run the animation.
Do your walking sprites only consist of a single image?
If so, GameMaker sets image_index to 0 when you set sprite_index to such a sprite.

To fix this, you would have change your step event to:
Code:
depth = -y;

if (path_position == 1) {
    sprite_index = Ichigo_frente_drcha;
} else {
    if (direction >= 270 or direction <= 0) {
        sprite_index = Ichigo_andando_frente_drcha:
    }
    
    if (direction >= 90 and direction <= 180) {
        sprite_index = Ichigo_andando_espalda_izquierda;
    }
    
    if (direction >= 181 and direction <= 269) {
        sprite_index = Ichigo_andando_frente_izquierda;
    }
    
    if (direction >= 1 and direction <= 89) {
        sprite_index = Ichigo_andando_espalda_drcha;
    }
}
 
S

shostifrosty

Guest
Now it works! Hallelujah!! Thank you so much!!

And the rest thank you too! I know it takes time to read someone else's thread and reply and help, so I really appreciate it. I'm a super noob in programming and I try to learn a little every day, so I can crawl out of this ignorance xD.

Now I understood how to make that works, it's time to think how to add more actions there to make the people feel really alive! ^___^
 
Top