• 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]Multiple collision masks?

AriesGames

Member
Hello everybody,

I am wondering if there is a way to create multiple collision masks for the same instance of an object.
Or if there is a way to change the size of the same collision mask as you need it?

I have a 2.5D game and for example the movement collision mask will be different from the shooting one.
The movement one will be at the base of the instance while the shooting one somewhere around the middle of the instance.

Here is an example, which obviously can't have the same collision mask.
I still need to rethink the shooting collision, but the principle is the same.

Thanks for the help. :)
 
S

Silver_Mantis

Guest
Hello everybody,

I am wondering if there is a way to create multiple collision masks for the same instance of an object.
Or if there is a way to change the size of the same collision mask as you need it?

I have a 2.5D game and for example the movement collision mask will be different from the shooting one.
The movement one will be at the base of the instance while the shooting one somewhere around the middle of the instance.

Here is an example, which obviously can't have the same collision mask.
I still need to rethink the shooting collision, but the principle is the same.

Thanks for the help. :)
For extra collisions for my player character, I just use invisible objects.
I know this method isn't the most optimized when using lots of them, but in my case I only need one extra one for the shield of my character to spawn and de-spawn when I push a button.
I don't see the harm in doing that for you character either. Just create an object that follows the player's X and Y through the step event. (Make that object's mask cover the area you want.)
Next, toggle off it's visibility. When that object is hit, have it effect the players health instead of the collision mask. ;)
 

AriesGames

Member
@Silver_Mantis This is not an option, let me explain.

I thought the same a few days ago and had the same concept implemented, using invisible objects as collision masks.
It's not a good idea...

The player needs two masks but so does the enemies. Which are multiple instances of the same object...maybe you see where this goes.
Memory is not a problem in this case since I wouldn't have many enemies anyway.
The problem is that at some point you will have to call a with function even in the enemy object.

With functions can generalize the instances and they all start to apply the code beyond that with function. They all start to behave the same beyond that with call.
Sure...you can apply code to each instance by their id and stuff...but why do that?

I have an idea...of changing the same collision mask by code by need.
But then the x,y axis problem occurs, you need to determine from which way the enemy/player are coming. Which is not an easy task to do.
I am starting to think of an alternative in point_direction and other things...but since I am a newbie I am having a hard time figuring it out.
 
S

Silver_Mantis

Guest
@Silver_Mantis This is not an option, let me explain.

I thought the same a few days ago and had the same concept implemented, using invisible objects as collision masks.
It's not a good idea...

The player needs two masks but so does the enemies. Which are multiple instances of the same object...maybe you see where this goes.
Memory is not a problem in this case since I wouldn't have many enemies anyway.
The problem is that at some point you will have to call a with function even in the enemy object.

With functions can generalize the instances and they all start to apply the code beyond that with function. They all start to behave the same beyond that with call.
Sure...you can apply code to each instance by their id and stuff...but why do that?

I have an idea...of changing the same collision mask by code by need.
But then the x,y axis problem occurs, you need to determine from which way the enemy/player are coming. Which is not an easy task to do.
I am starting to think of an alternative in point_direction and other things...but since I am a newbie I am having a hard time figuring it out.
Ah I see.
Well actually I have an idea for ya myself!

So because collision is only needed below the hitbox of the character, why not do collision checks manually?

For example, let's say your character is 100px tall. That is the Black Box in this diagram.



Let's say you only need to cover 1 - 70 pixels. This is your collision mask for damage. That arrow is A.
The rest should be the area needed for collisions, that is Area D.
So from your player's origin (Arrow B), use place_meeting(); to detect your collision, UNDER the collision mask for damage. You can have 4 points of collision, marked by the green circles (Arrow E).
Place the points from this distance of your origin, marked by arrow C.

This way you only have one collision mask, but still detect collision.
 

GMWolf

aka fel666
Invisible objects are fine.
If you use the with call, then don't do it on the object (or DO NOT do with(obj_foo))

Instead, call it on an instance.
When you create your invisible object, keep the I'd around.
Code:
my_hitbox = instance_create(X, y, obj_hitbox);
Then, wherever you need it, reference my_hitbox instead of obj_hitbox.
Code:
with(my_hitbox) {
 //Do whatever
}
I see way too many people getting in trouble when using objects instead of instances... Like 3 just in the past couple hours? It's a real problem...
 

AriesGames

Member
@Fel666
First thanks for responding,
Now, what you're actually saying is that by
Code:
hitbox = instance_create(X, y, obj_hitbox);
everytime you create an instance of that object it stores even the ID in that var?

Now back to the topic, so theres actually no way to edit the size of a mask?
 

GMWolf

aka fel666
@Fel666
First thanks for responding,
Now, what you're actually saying is that by
Code:
hitbox = instance_create(X, y, obj_hitbox);
everytime you create an instance of that object it stores even the ID in that var?
Yes, it will store the unique instance ID.

Seems like you do not understand the difference between an instance and an object. Do you?
 

AriesGames

Member
@Fel666 The only thing I understand between them is that the object is a parent of each instance.
That each instance reads the code independently from each other instance of the same object.
Recently I learned that each instance is created by the obj with a unique ID.
I don't understand much...I don't know what's so much to understand either.

Well...it struck me why I never thought that vars can store ID's too...

@Online Handle I am using GM 1.8, Spine it's not even build-in. Maybe on my second project, if there will be one which I hope, I will turn to GM 2.
But thanks for the help anyway. :)
 

GMWolf

aka fel666
@Fel666 The only thing I understand between them is that the object is a parent of each instance.
That each instance reads the code independently from each other instance of the same object.
Recently I learned that each instance is created by the obj with a unique ID.
I don't understand much...I don't know what's so much to understand either.

Well...it struck me why I never thought that vars can store ID's too...

@Online Handle I am using GM 1.8, Spine it's not even build-in. Maybe on my second project, if there will be one which I hope, I will turn to GM 2.
But thanks for the help anyway. :)
Here, read this!
https://forum.yoyogames.com/index.php?threads/whats-the-difference-objects-and-instances.29005/
 

AriesGames

Member
@Fel666 Better respond before the day ends.
I knew it's a template but I didn't know how to explain it.
Thanks for the response, really appreciate it. Reading it now.
 
Top