[solved] how to check for [not on collision with solid]

Just started using Construct 2? Post your questions here

Post » Thu Jun 16, 2016 10:46 am

Hello,

I was wondering since quite some time: Is there any good way to check whether an object is not touching a solid?

Example: When the player collides with a solid, the text changes to "is on collision". Now when the player moves (or jumps or falls) away from the solid and does not touch it anymore, the text is supposed to change to "is NOT on collision".

Below you can see one possible solution, but I think this is very hard on the memory because at every tick, it has to check every single solid whether they are the nearest to the player and then whether they are (almost) touching the player. Or am I misunderstanding this?

Image

I am looking forward to better ideas. Thank you!

https://www.dropbox.com/s/ww2safdaowxht ... .capx?dl=0
Last edited by strangeDays on Thu Jun 16, 2016 12:00 pm, edited 1 time in total.
B
13
S
2
Posts: 21
Reputation: 721

Post » Thu Jun 16, 2016 11:16 am

One option might be:

Player Is Overlapping Solid at offset (1,1) -> set text to 'On Collision'
System Else -> set text to 'not on collision'
If your vision so exceeds your ability, then look to something closer.
Moderator
B
136
S
31
G
86
Posts: 5,486
Reputation: 59,758

Post » Thu Jun 16, 2016 11:52 am

Thank you for your suggestion. I tested it and it adds 1 additional collision check per tick for every solid in the level. Not too shabby.

But in the meantime I have found another solution which adds no additional collision checks per solid.

Image

When the player collides with a solid, a helper object is created at the same position of the solid, but with two differences: It is a little bigger than the solid and it does not have solid behaviour so that the player can overlap with it. So now you only have to check one single object for overlapping with the player. If the helper object overlaps with the player, the solid "kind of overlaps" with the player, too. If the helper object suddenly doesn't overlap with the player anymore, neither does the solid. In that case, the helper object is destroyed and the text is changed to "not on collision".

Now of course it's gonna get a little tricky when you have different types of solids with different forms and sizes but maybe rexrainbow's nickname plugin can be of help then. If I decide to investigate that matter further, I will check back to this thread.

https://www.dropbox.com/s/noyf149ldkgr5 ... .capx?dl=0
B
13
S
2
Posts: 21
Reputation: 721


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests