# How can I make relative movement in GameMaker studio?

I know I can change the hspeed and vspeed properties on my object. Assume I do it for the directional diamond in a squared-style movement game (not necesarily snapping to tiles, but it could). So the following scenarios apply (for any constant K) for my obj_Hero object:

• Pressing UP: vspeed is -K, hspeed is 0
• Pressing DOWN: vspeed is K, hspeed is 0
• Pressing LEFT: vspeed is 0, hspeed is -K
• Pressing RIGHT: vspeed is 0, hspeed is +K
• Otherwis: vspeed and hspeed are 0
• Only one directional arrow at the same time will be considered (the last pressed).

My player starts from position of an obj_Start object, and wins when reaching (colliding) an obj_End object. In the meantime, an obj_Enemy will be chasing the player using a step avoid strategy to avoid the player. The player loses if the enemy collides with him. Assuming I can correctly select the enemy current direction sprite, I'm done.

So far, so good.

Now assume some parts of my game have moving platforms. They have a specific platform speed vector (PSH, PSV), assuming I have such constants.

I know I could always condition my player movement speed to be:

• (K + PSH, PSV) for player moving right
• (-K + PSH, PSV) for player moving left
• (PSH, K + PSV) for player moving down
• (PSH, -K + PSV) for player moving up
• (PSH, PSV) for player not moving

But... How do I alter (relative to the platform movement, as I do with the player) the enemy movement when it is actually generated by the step avoiding strategy?