Grid movement doesn't detect collisions

Post your own tutorials, guides and demos.

Post » Wed Mar 03, 2010 3:05 am

I tried fixing it using detectors, but that didn't work.
B
2
G
2
Posts: 10
Reputation: 670

Post » Wed Mar 03, 2010 6:19 am

Well to start off, thats not a collision event, thats a ... erm, not overlapping event. :wink:
Any way what I think is happening is that your detectors are past the trigger point when the overlapping starts.
Image Image
B
161
S
48
G
91
Posts: 7,359
Reputation: 67,273

Post » Wed Mar 03, 2010 8:15 am

Your detectors are flawed.

Move the enemy one grid space closer to the hero and it will work. If you have an even number of gridspaces between the two then you will get a proper collision, but if you have an odd number then you won't because your detectors are passing right over their targets.

Anyway, try checking for overlap at offset before moving. You don't need detectors at all for this.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Mar 03, 2010 4:50 pm

[quote="deadeye":2e7ivcgn]Your detectors are flawed.

Move the enemy one grid space closer to the hero and it will work. If you have an even number of gridspaces between the two then you will get a proper collision, but if you have an odd number then you won't because your detectors are passing right over their targets.

Anyway, try checking for overlap at offset before moving. You don't need detectors at all for this.[/quote:2e7ivcgn]

Yeah, it only works if I move the enemy 1 space closer to the hero like you said. I'll play around with it some more to see if I can make it work all the time.
B
2
G
2
Posts: 10
Reputation: 670

Post » Wed Mar 10, 2010 12:40 am

ok, so I played around with it some more but I still can't get it to work all the time (even if there are an odd number of grid spaces. The overlapping at offset didn't work either. So, is the grid movement broken or what do I need to do to get a proper collision no matter what?
B
2
G
2
Posts: 18
Reputation: 686

Post » Wed Mar 10, 2010 1:07 am

No its not broken. It just doesn't do what you want it to. All it is is a movement, and that's all it does.
There are basically four ways to do what you want.
1. An on collision event
This is a trigger once event, meaning it wont trigger it again even if the objects are overlapping.
2. An overlapping event
This is a continuous event, meaning the it will trigger as long as the objects are overlapping.
3.An overlapping at offset event
Same as overlapping, but it only checks one side x, and y. If you want it to check on all 4 sides you will need to add additional conditions for positive x, negative x, positive y, and negative y.
4. Distance(x1,x2,y1,y2) Distance between points
This isn't an event, but an expression. You can use it in a comparison to tell the distance between objects.
Example:
>system compare distance(sprite1.x,sprite1.y,sprite2.x,sprite2.y) < 32
-> do this
Image Image
B
161
S
48
G
91
Posts: 7,359
Reputation: 67,273

Post » Wed Mar 10, 2010 1:36 am

Thanks, I will try some of those solutions out later, but I have a question.

Why does moving a sprite using events ignore collisons, but using the default movement it detects collisions? I made an example to help you understand what I mean.
B
2
G
2
Posts: 18
Reputation: 686

Post » Wed Mar 10, 2010 6:05 am

The answer is there really is no collision event. The movement was designed to make sure that npc, and player movement could be controlled by not allowing object to go over other objects with the solid attribute... well at least not unless you force it to like in the second layout.
Image Image
B
161
S
48
G
91
Posts: 7,359
Reputation: 67,273

Post » Wed Mar 10, 2010 6:29 am

I see what you mean. The movement just wasn't designed to detect collisions when you a move a sprite through events. I just assumed that it would because it detected collisions without events.
B
2
G
2
Posts: 18
Reputation: 686

Post » Wed Mar 10, 2010 3:19 pm

You're going about things kind of backwards here anyway. If you want solid collisions with your NPC's then check for overlap at offset with a solid in the next gridspace before moving them, rather than trying to stop their movement after it's already begun.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Next

Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests