I think I was using the move_towards_point function incorrectly. I discovered that I could not make the object move down.

In the create event, if I include the code move_towards_point(x,y,10);, the object in question moves to the right:

<code>move_towards_point(x,y,10)</code> moves the red circle to the right.

If I include the code move_towards_point(-x,y,10);, the object moves to the left:

<code>move_towards_point(-x,y,10)</code> moves the red circle to the left.

I wanted to make the object move up, so I left x and used move_towards_point(x,-y,10);. It moved up as I wanted.

<code>move_towards_point(x,-y,10)</code> moves the red circle upwards.

Yesterday, I had the need to make the object move down. That's where my dilemma began. I thought to use move_towards_point(x,+y,10);. It did not work; the object moved to the right, as in the first demonstration. I tried move_towards_point(0,y,0);. The object moved to the left, again, as in the second demonstration.

I began to suspect that I was not using the function correctly. By the name, I assumed it would move an object to a certain specific point. I went back to test move_towards_point(-x,-y,0);, and the object move diagonally:

<code>move_towards_point(-x,-y,0);</code> moves the red circle upwards and to the left.

I found the solution to all cases of movement:

  • Down : move_towards_point(obj_Bola.x,obj_Bola.y+1,10);
  • Up : move_towards_point(obj_Bola.x,obj_Bola.y-1,10);
  • Left : move_towards_point(obj_Bola.x-1,obj_Bola.y,10);
  • Right : move_towards_point(obj_Bola.x+1,obj_Bola.y,10);

The explanation seems to be that I am now using the x and y, relative to the object. When I do not want to change it's position on any of it's axis, I simply do not add any value. On the axis that I want the object to move in, I add or subtract a value.

One observation is that the value added or subtracted does not change the speed that the object moves, so move_towards_point(obj_Bola.x,obj_Bola.y+99999,10); moves the object down with a speed of 10.

I would like to know the logic behind move_towards_point, and if the way I solved my problem is the right one.

  • \$\begingroup\$ +y is the same as y \$\endgroup\$
    – Bálint
    Mar 23, 2017 at 22:43
  • \$\begingroup\$ Yes, I know, but at the time I thought it might have some effect \$\endgroup\$ Mar 23, 2017 at 22:46
  • 1
    \$\begingroup\$ you could think of the function having the name move_towards_the_points_passed_in_the_parameters_from_the_current_position_and_at_the_specified_speed do not confuse with move_with_the_speed_vector_given_in_the_paramteres (i.e. setting hspeed and vspeed] - to emphasise, the parameters are the target position, not the direction of movement, nor the speed vector to use. \$\endgroup\$
    – Theraot
    Mar 23, 2017 at 23:16
  • \$\begingroup\$ Welcome to GameDev! Note that there were a few redundancies (things you were telling us twice) in your question, so I have removed them for an easier read. I have also formatted the structure to make it easier to read (everything stated is in a "timeline" order of what you did, instead of jumping back and forth, for example). I also removed the part about using a translator. Note that if we have any questions, we will ask via comments. You do not need to ask, as that is what comments are for. \$\endgroup\$
    – Gnemlock
    Mar 23, 2017 at 23:30
  • \$\begingroup\$ @Gnemlock Thank you for your reception and editing!!! \$\endgroup\$ Mar 24, 2017 at 0:38

2 Answers 2


move_towards_point() Makes the character go to a specific position, it's not intended to use it for general movement.

For example, if your character is at (100, 100) and you use the function with (200, 200), then it starts moving diagonally in the right-down direction.

Because the x coordinate 0 is at the left edge and the y coordinate 0 is at the top, if you enter these values, the character starts moving towards those edges.

If you enter the character's positions, it defaults to right.

To make the player go in a specific direction, you need to add some amount to the x and y coordinates. For example, to move down you do

y += 1;

move_towards_point makes the object move towards a particular point - as its name implies.

If the object is at coordinates 200,200 and you do move_towards_point(x, -y, 10) then you are telling it to move to coordinates 200,-200 which is off the top of the screen. (10 is the speed)

If the object is at coordinates 200,200 and you do move_towards_point(-x, -y, 10) then you are telling it to move to coordinates -200,-200 which is off the top-left of the screen.

If the object is at coordinates 200,200 and you do move_towards_point(x, y, 10) then you are telling it to move to coordinates 200,200. But it's already there, so I guess it arbitrarily moves right. (Personally, I'd expect it to not move if you tell it to move to where it already is...)

  • \$\begingroup\$ This doesnt appear to add anything new ontop of the previous answer \$\endgroup\$
    – Gnemlock
    Mar 24, 2017 at 7:06
  • \$\begingroup\$ The function uses vector math under the hood, and because a 0 length vector can't be normalized correctly, it returns a vector pointing to rigjt. \$\endgroup\$
    – Bálint
    Mar 24, 2017 at 7:52
  • \$\begingroup\$ @Bálint That is not a good reason for the function to behave the way it does. "Under the hood" the function is perfectly capable of computing the length of the movement vector. \$\endgroup\$
    – user253751
    Mar 24, 2017 at 10:35
  • \$\begingroup\$ @immibis A vector with the length 0 would prodice a division error on normalizing. You usually have a fixed position for the object to go to, stuff like this doesn't hapoen \$\endgroup\$
    – Bálint
    Mar 24, 2017 at 10:46
  • 1
    \$\begingroup\$ @Bálint You don't normalize the vector and then check if it's zero-length. You calculate how far the object should move in one step, then see if the target is closer than that, and if so you move the object directly to the target position. Only if the target is further away than that do you need to calculate a normalized direction vector. \$\endgroup\$
    – user253751
    Mar 25, 2017 at 7:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .