Just a random though about collisions

Discussion and feedback on Construct 2

Post » Fri May 16, 2014 8:03 pm

I've always though it would be a stupid idea but, I don't know why, it seems that in the cases where every concerned object is on screen and has collisions activated, picking the nearest object only before doing the collision check seems to work a little better than actual collisions check alone (at least it seems from what the debugger stated), so I wonder, wha tdo you think about it?

Image
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Fri May 16, 2014 8:31 pm

This seems kinda cool, but I can see a problem if there were multiple "Sprite" objects. If there was 2 Sprite objects (at the same distance) trying to collide with Sprite, it would only detect 1 of them, right?
Or what if one of the Sprite's was stretched a bit, the distance is still the same but could be touching Sprite2, but then a 2nd Sprite that isn't stretched could be closer but not touching Sprite2.
Pretty interesting nonetheless! I reckon this could be use in certain ways :P
B
51
S
20
G
10
Posts: 571
Reputation: 9,819

Post » Fri May 16, 2014 8:35 pm

I'm not sure it's optimal for every situation, Jase mentioned some of the problems, but it seems to reduce CPU use when I've used it in the past, but use 'is overlapping' instead. 'On collision' can do more checks than 'is overlapping' and exporting an event with a trigger as a subevent like that as I understand it basically gets copied and reordered on export so the trigger is the first condition (I'm not 100% positive of that but I seem to recall that's how it works), so I think your event is actually running as:

on collision
For each
Pick nearest
Moderator
B
95
S
34
G
33
Posts: 3,006
Reputation: 27,874

Post » Fri May 16, 2014 8:41 pm

@Jase00 : Indeed I didn't though about those cases

I was trying to work on a document about C2 and organisation and performances, and this case troubled me for a little while so I went to try it, even though I do not think It'll figure directly inside since the requirement it has, but I could use it as a potential exemple.

@Arima: I didn't know about collisions doing more checks than overlapping, but I'll try it.

As I said, It was more a though rather than a real need
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Fri May 16, 2014 8:44 pm

I edited my post to add a point I should have put in there in the first place, just want to make sure the point wasn't missed.
Moderator
B
95
S
34
G
33
Posts: 3,006
Reputation: 27,874

Post » Fri May 16, 2014 8:55 pm

@Arima : from my experience it doesn't work exactly like this but I could be wrong on that. (also the debugger shows the expected number of collisions check, and I do not think the exporter would alter the game's logic like that), it seems more like a visible scope of event, Also the "on collision" is not a trigger (or not directly a trigger), since it makes supplementary checks to verify if the collision needs to be checked (for my understanding, a trigger wouldn't have to be really checked like that, it would happen or be called most likely)
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Sat May 17, 2014 12:04 am

I'm not 100% sure how it works either. Very very early in C2's development I seem to recall triggers weren't allowed as subevents and I asked Ashley to allow them - and I thought he said it would work as I described, but it was so long ago that I might not be remembering it correctly. Or maybe different triggers work differently, I remember the one I was talking about in particular was 'on mouse clicked' which wouldn't affect picking if it was put at the top of a copy of the event tree. Again, I might be wrong about that though.

I also wasn't entirely sure how on collision works so I did a test. There was a thread a while ago from someone who reported getting more checks with on collision than with is overlapping. Using your events in your first post with one instance of sprite and sprite2, I got 1 check per tick. If I put the collision condition on the top, I got two checks. If I add another event:

Every tick
- set sprite position to random(10), 0
- set sprite2 position to random(10), 0

...the collision checks are upped to 4, so it does seem C2 has some sort of automatic extra checks happening when an object is told to move by an action, but not when filtered by parent conditions. I tried duplicating the every tick event, but it didn't affect the checks, so my guess is C2 takes a note of which objects moved and then does an extra check at the end of the event sheet, or something like that.

Either way, it does seem to reduce the checks to the same amount regardless of using on collision or is overlapping.
Moderator
B
95
S
34
G
33
Posts: 3,006
Reputation: 27,874


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 20 guests