• 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!

SOLVED Collision checks with all children of an object

A

aikky

Guest
I wanted to generalize player object collisions with the children of an object I've called o_collidable so I only have one collision event in my player events. How can I go about this. This means, if objects a, b and c are children of o_collidable, the player will collide with any of them. Am I thinking about inheritance wrong wth GML?
 
A

aikky

Guest
Okay, got it. I created the parent object, and added any objects I wanted as children. Then, by only having one collision detection event (to see if I was colliding with the parent object), all children were captured.

So just in case anyone stumbles upon this and wonders why that's the case, inheritance works the same way in GML as it does in Java. Say you have a parent object (class, in Java), called o_animal. The animal can make a sound, has variables such as hair = true, likes_pets = true, etc. Now we make a child object, o_dog. Dog inherits these traits which we can then modify. We can further make child objects like o_hairless_dog where hair = false and likes_pets = false.

The magic in this is that, in all cases, the hairless dog is still a dog, and dogs are still an animal. So, all of these are captured by the script for the parent object.
 
Top