[SOLVED] Is it possible to check from which side same object is colliding and then apply action to only one of that object?

I know i can check if same object is colliding with another object of same type
But is it possible to check from which side?
Like let’s say i spawn 2 player objects and then horizontally they stand next to each other just like here
image
And now is there a way to check if there is another player object on the right from it?

And IF yes then is it possible to for example change object animation to something else that will affect ONLY the player object on the left?
And the player object on the right remain unchanged

Making another player object is no option for me since i would need tons of that player objects on map

So like IF next to THIS object is same object right from it change THIS (the one on the left) object animation
So since object on the right don’t have same object next to it from the right side then it should be unchanged

Check the explanation in this link. You can use the same method to check in any direction you like.

Thanks
I understand what it means but i don’t have any idea how to do it?
How do i add object to existing object?

It looks like :

Markers

I understand everything here and seems better idea than what i was planning to do
Let me show you what i try to achieve because i am not sure if it helps me

What is left from player is exactly the same that is right from player
Difference is on the right i used objects for which i manually set different animation
But i wanted to streamline that process and on map creation just run some condition to check from which side stones are colliding and then change their animation accordingly kinda like tiled map
Then i don’t need that markers anymore until i destroy 1 stone (there will be to destroy more at once)
So i could just check before stone destruction how much stones are touching one that being destroyed then set change their animation accordingly and delete destroyed stone and simply remove markers again
I am capable of using your method to do so since i understand the principal here and i would be able to implement it as i want i am just not sure would it work for every stone
I think i will need something to check like if THIS stone point TOP + LEFT is colliding with other stone but not on point BOTTOM + RIGHT
If that makes any sense
I won’t be able to check that for few hours so if you know the answer i am all ears

You could look at giving each point a value; top - 1, left - 2, right - 4 and down - 8. Then add up the numbers of the markers that are on other stones. If you know your binary, you’ll realise that they make up a 4 digit binary number.

The neat thing with that is you can check whether bits are set quite quickly using the binary operator “&”. You’d use it to check that the value & 3 = value, which means it checks that the top and left (1 + 2 = 3) are set, and nothing else. I’m not sure if you’re familiar wit binary operators, can explain later if you’re not.

The binary operations will need to be done in JavaScript,as there are none in GDevelop. This is fairly easy with a few lines in a JavaScript event.

I fully understand what you are trying to explain to me but i have no idea how to implement it or even where
I mean i understand the method i don’t understand the mechanics
So explanation with example would be cool and i am not in rush with it

I did try your method with markers and it work but only if i have 1 marker per object
I was unable to achieve same result for 4 markers from 1 object

To make it clear what im trying to do is that i have object called Stone
It have 4 points Top Left Right and Bottom as you can see here

I was trying change animation of the stone depending on which points are touching other stones
(to be clear i did try your method where i created different objects on each marker like pxT pxL pxR pxB) so depending from which other stones are touching each other they would get corresponding markers
But it did not work
So do you have any times how to achieve that?
Also there is condition “point inside object” it works perfectly but not for the same object
If i surround 1 stone by 4 trees (1 from each side) and check if point of stone is inside of tree
it works but when i set that condition to stone and surround 1 stone with 4 stones it does not work

Can you share a screen shot of the events?


I’m guessing you’re using a repeat for each stone to check the neighbours. When you do this, you are filtering the list of stone objects that GDevelop works with to just the one you are iterating over. So those points will not be within another stone, because GDevelop doesn’t have them in the list of stones.

The way I would approach this is to have two repeat for each stone loops. The first loop you place a marker at each point for each stone and give each marker the binary value of the point. Link the markers to the stone.

Then in a following event that’s a sibling of that repeat (i.e. at the same level), remove any markers that are not in collision with a stone.

Finally have another repeat for each stone loop, getting all the markers linked to the stone. Add up the marker values and remove them.

Although probably not the ideal or most efficient way, it’s a simple and understandable method.

Yes i do use repeat for each and you already know the result of that
Also i deleted whole event since it did not work and moved to “check if point is inside object collision mask”
Which also did not work so i also deleted that
So i have nothing to show you but anyway it was exactly as you described it
And i was thinking about your idea with binary numbers
I was wondering maybe some variables would help in this situation?
Like set variable of a stone accordingly to how many of his markers are occupied by other stones and save that into variable then i could based on the variable of stone change it’s animation at will
like for each stone with variable 1248 set animation to blablabla
Or am i wrong?

Yes, that’s very similar to the binary method I am suggesting, but instead with that you add the values so the maximum you’d have is 15 (1+2+4+8).


Nope, very much on the right track.

Ok could you make example for me like you did before?
Because as you see i understand the mechanics but lack knowledge how to do it

You set me on right track with this solution
And guess what? It bloody works
2022-11-06_15_54_2HrL2FfxO6_GDevelop
Big THANK YOU for your soliution :slight_smile:
This is still WIP version :wink:

4 Likes