SOLVED PATHS: Get hspeed and vspeed of an instance ??

FoxyOfJungle

Kazan Games
Hello,

I'm trying to acquire the vertical and horizontal speed of an instance in which is using a path, but apparently there is no way to do it...


I just did this:

CREATE EVENT:
GML:
my_path = -1;
alarm[0] = 2;
STEP EVENT:
GML:
// hspeed and vspeed
hsp = x - xprevious;
vsp = y - yprevious;
ALARM 0:
GML:
path_start(my_path, 1, path_action_continue, false);

But the variables hsp and vsp are always 0.
I also tried to define the xprevious and yprevious variables in the Begin Step event but it doesn't work either:

GML:
xprevious = x;
yprevious = y;
I also used the same code above using alarms set to 1, 2 and 3, and it didn't work. I can't just get the horizontal and vertical speed of the instance.


I will be grateful if you can help me with anything.
Thanks!
 
Last edited:
D

Deleted member 16767

Guest
Have you tried something like this @FoxyOfJungle ?

GML:
if keyboard_check(vk_control) && keyboard_check(ord("1"))
{

path_id = path_add();
mp_potential_path(square_path, x, y, 3, 4, 0);
path_start(square_path, 20, path_action_stop , true);

path_delete(path_id)

}

if mp_potential_path(square_path, x, y, 3, 4, 0)
{
    path_assign(path_id, square_path);
}

Ah, nevermind. I didn't see you had path_start.
 
Last edited by a moderator:

FoxyOfJungle

Kazan Games
Have you tried something like this @FoxyOfJungle ?

GML:
if keyboard_check(vk_control) && keyboard_check(ord("1"))
{

path_id = path_add();
mp_potential_path(square_path, x, y, 3, 4, 0);
path_start(square_path, 20, path_action_stop , true);

path_delete(path_id)

}

if mp_potential_path(square_path, x, y, 3, 4, 0)
{
    path_assign(path_id, square_path);
}

Ah, nevermind. I didn't see you had path_start.
Unfortunately your solution doesn't work, but thanks for your help :)


You need to set hsp and vsp in the End Step Event.
Your solution works, thank you! I just don't understand why in other cases I use it in the Step Event (before the collision part) and it works perfectly, only with paths that I needed to put in the End Step. 🤔


Have you tried using hspeed and vspeed?
My purpose is to use a custom variable, really, but thanks for the help. :)
 

TheouAegis

Member
Your solution works, thank you! I just don't understand why in other cases I use it in the Step Event (before the collision part) and it works perfectly, only with paths that I needed to put in the End Step. 🤔
Because you are relying on internmal functions. Internal movement functions do not run until after the Step Event and before the End Step event. Consequently, xprevious and yprevious, which are set during the Begin Step event, will always be the same as x and y until the latter get changed, which doesn't occur until after the Step Event because you are using internal movement functions.
 
Top