Hey guys!
I stumbled upon a rather strange behavior of GMS2 regarding paths, path_position and x/y coordinates.
Following scenario:
I have an "obj_player" that can move 2D platformer style.
A second object, called "obj_pathpos" (for path position) is assigned to path "pat_test".
pat_test goes from left to right, while also slightly going down.
Now I want obj_pathpos to always match the x-coordinate of obj_player.
So my code is:
(code is only for the case player x is greater)
So, if the x-coordinate of obj_player was to increase above the x-coord. of obj_pathpos, it would increase the
path_position of obj_pathpos in 0.01 increments, moving it to the right along the path, until this is no longer true.
The problem is, this does not seem to work. The game freezes completely everytime.
Why is that? Am I missing something obvious?
At a certain path_position, the x of of obj_pathpos becomes inevitably greater than obj_player.x, no?
If I replace "path_position" with just "x". so:
...it works just fine (if I comment the "path_start()" out, of course.
Also, if I use a simple if-statement instead of "while", it seems to work, but then it's not following fast and precice enough.
Has anyone any idea, why my code is not working?
Thanks in advance!
I stumbled upon a rather strange behavior of GMS2 regarding paths, path_position and x/y coordinates.
Following scenario:
I have an "obj_player" that can move 2D platformer style.
A second object, called "obj_pathpos" (for path position) is assigned to path "pat_test".
pat_test goes from left to right, while also slightly going down.
Now I want obj_pathpos to always match the x-coordinate of obj_player.
So my code is:
Code:
while (x<obj_player.x)
{
path_position+=0.01;
}
So, if the x-coordinate of obj_player was to increase above the x-coord. of obj_pathpos, it would increase the
path_position of obj_pathpos in 0.01 increments, moving it to the right along the path, until this is no longer true.
The problem is, this does not seem to work. The game freezes completely everytime.
Why is that? Am I missing something obvious?
At a certain path_position, the x of of obj_pathpos becomes inevitably greater than obj_player.x, no?
If I replace "path_position" with just "x". so:
Code:
while (x<obj_player.x)
{
x+=0.01;
}
Also, if I use a simple if-statement instead of "while", it seems to work, but then it's not following fast and precice enough.
Has anyone any idea, why my code is not working?
Thanks in advance!