# Moving Objects Relatively With Their Parent Object [Gamemaker]

I have an object type, oFur, instances of which are generated in a random distribution over the sprite area of a parent object, oFurArea.

However, I would like the oFurArea to change its image_xscale and image_yscale dynamically, as well as its y position. This is easy to do, but I would also like all of the oFur instances to move with their parent (i.e. change their own 'y' values), whilst maintaining their relative positions on the parent object.

Either I'm having a brain-fart, or I cannot work out how to do this. Any help would be appreciated.

• You mean you want to move oFurArea by foo and then move every oFur by foo too? – DH. Jun 9 '16 at 15:20
• I'm not sure what you mean by foo? The oFurArea changes its y every step at a ChangeRate variable. I would like the oFur to change its y position at this same rate whilst maintaining its position relative to the oFurArea. I realise that I could just duplicate the y-changing code in the Step Event of the oFur, but a more elegant solution would be to update the oFur's 'y' variable every step based on oFurArea's y. – Bonfire Dog Jun 9 '16 at 15:29
• Ah, I see now what you mean by foo. en.wikipedia.org/wiki/Foobar – Bonfire Dog Jun 9 '16 at 15:29
• You can try this, maybe it will work: in the create event save in a variable the difference between oFur.y and oFurArea.y. Then on step, make oFur.y = oFurArea.y + difference;. – DH. Jun 9 '16 at 15:33

Thanks to @DH above, I've managed to find an elegant solution to this, I think.

Every step, the oFurArea updates its Difference variable as the distance between its original y value and its current y value. This needs to be done every step, as oFurArea is constantly moving:

Difference = OriginalY - y


Each oFur instance than also has an OriginalY value, set upon Create. Every step, they set their own y value to a distance relative to oFurArea's distance.

Therefore, if the distance between oFurArea's current y and its OriginalY was 15 pixels, each oFur's y would be 15 pixels from its own OriginalY as well. This keeps everything relative to each other.

So, in the oFur's Step event:

y = OriginalY - oFurArea.Difference


I think this solution is elegant as it only requires two variables and only two lines of code. Thank you for the help, DH.