Make an Object Move when Another is Destroyed?


Gary Alexander Stott

Hey guys,

I'm working on a battle mode for my Pong game, and I'm trying to achieve this:

When a paddle fires its laser and the laser hits or misses the other paddle (despawning on contact or despawning upon leaving the room),the ball (which, all this time, is outside the room, waiting to come back in after the laser hits/misses) moves back to its starting position with the correct hspeed and vspeed values.

Making the laser despawn after hitting or missing is easy enough, of course, and I've achieved that already, but how do I affect the position & speed of another object (the ball) in relation to the laser's status? I'm not even entirely sure in which object to write this code.

Thank you.


Your Creator!
You can add some code in the destroy event of your object that gets destroyed. There you could say something like:

In gm you can say: objectname.variable name=newvalue;

I hope that can help you.

Gary Alexander Stott

Thank you! That's perfect. I'm fairly new to GMS, so every time I learn a piece of code like this, it's like learning a new word I can use in a bunch of different contexts. I knew you could affect the x/y values of an object that way, didn't realise you could affect stuff like speed! Thanks again :)