0 Favourites

Grid movement doesn't detect collisions

This forum is currently in read-only mode.
  • I tried fixing it using detectors, but that didn't work.

  • Well to start off, thats not a collision event, thats a ... erm, not overlapping event.

    Any way what I think is happening is that your detectors are past the trigger point when the overlapping starts.

  • 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.

  • 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.

    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.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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?

  • 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

  • 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.

  • 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.

  • 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.

  • 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.

  • Just want to highlight something already said cuz I was getting frustrated a week ago with the same problem.

    [quote:2jbnjf83]"in the next gridspace before moving them" by deadeye

    That next gridspace part is really important. I was sending the character a variable number of steps and he would still walk over the barrier because he didn't reach an overlap till after he was already walking. Took me an hour or more of fiddling to figure out what was wrong.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)