• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How do I have an object teleport to another object upon collision?

N

Nintyboy

Guest
New developer here



Basically, once one of the people here touches that white square, they should be immediately teleported to a certain section within that white square.

My problem is, as soon as one person touches it, All of them are immediately transported to the exact same spot, not just one of them.

I'm using this code:


(The 20, 20 co-ordinates are just an example within that white square to use.)


I'm trying to figure out how to apply this only for the specific object that touched the square, not all of them at the same time.

Can anyone help me with this?
 

2Dcube

Member
Is the collision done with the Collision Event? In that case, the "other" keyword will get you the exact instance that you want to teleport.

For example, Collision Event in obj_WhiteSquare:
Code:
other.x = x1 + random(width);
other.y = y1 + random(height);
 
N

NodziGames

Guest
This is where GameMaker becomes confusing. Objects are not instances. An object is basically a wireframe of characteristics, and when you drop it in your room or call instance_create, you generate what we call an "Instance" of that object. An instance will have a unique ID to help you distinguish between the different instances of an object.

Please note that hard coding this value is also a bad idea. You'll have to find out which one of the instances you want it to act upon. There are 2 approaches that come to mind right away.

If you're calling that script from obj_child, you can replace obj_child.x to self.x, or just use the shorthand equivalent x.

The best solution in my opinion would be to use the collision event on the obj_child and put the logic in there, then just reference x.

Lastly, if you're using the collision event from the white square, replace obj_child.x with other.x. Other holds the ID of the other object involved in the collision.
 
N

Nintyboy

Guest
Thanks for the help. I figured out the problem myself while the thread was awaiting approval (though the other thing certainly works better than what I came up with, so thanks), and I realized I had made a dumb mistake.

I want whatever person that touches the white square to be placed in a certain section of that white square, until there's four people in it.

Upon debugging it I discovered that once the first person was teleported inside the square, it was still triggering the collision event.

Is it possible to remove the collision mask of an object through the code? Basically, once the person is inside the square, it shouldn't be triggering the collision event of the square anymore.
 

Bentley

Member
it was still triggering the collision event.

Is it possible to remove the collision mask of an object through the code? Basically, once the person is inside the square, it shouldn't be triggering the collision event of the square anymore.
Here is a simple solution:

o_person
Code:
// Create event
can_collide = true;
o_block
Code:
// Collision event with block
with (other)
{
    if (can_collide)
    {
        x = 20;    
        y = 20;    
        can_collide = false;
    }
}
But I would read the previous post about the difference between objects and instances.
 
Top