1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Make an Object Move when Another is Destroyed?

Discussion in 'Programming' started by Gary Alexander Stott, Jan 13, 2017.

  1. 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.
     
  2. Tthecreator

    Tthecreator Your Creator!

    Joined:
    Jun 20, 2016
    Posts:
    758
    You can add some code in the destroy event of your object that gets destroyed. There you could say something like:
    Obj_ball.hspeed=....;
    Etc

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

    I hope that can help you.
     
  3. 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 :)
     

Share This Page