I am trying to have my "obj_playership" move towards the Cursor on a single Axis. Prefer it to be the Vertical Axis. I tried doing this is an "Execute Code Box" in a step event

"direction = mouse_x" "speed = 1 " but the movement looks weird and does not do what I am trying to do.

To better refine my question I'm trying to have my "obj_playership" move just up and down in relation to the mouse, so if I'm moving my mouse up or down the obj_playership" will follow towards the mouse either up or down.


1 Answer 1


Just check where is the mouse based on the object's position:

if (mouse_y - y) > 0 {
} else if(mouse_y - y) < 0 {

This same code could be written in different ways but are a little bit complex to understand XD

y += sign(mouse_y - y);

The "direction" must be an angle, that's why it looks weird like this.

  • \$\begingroup\$ The first part is what I Was Trying to do thanks the second part is helpful too if I wanted something more instant. \$\endgroup\$ Commented Apr 17, 2019 at 1:38
  • 1
    \$\begingroup\$ If you think it moves slow you can use your own variable for speed. I've repaired a mistake on the second form \$\endgroup\$
    – Juanpa
    Commented Apr 17, 2019 at 14:55

You must log in to answer this question.

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