Annoying hit detection, either too much or too little


(John Andersson) #1

I have a rain system going on, if it hits entities or the grond, the rain “explodes”. It works perfectly fine on the ground, which is part of a tilemap.

However, when I try to make it pop on entities which have the same x as the ground (they are blocks you can activate, hence not having them part of the ground), then either the rain pops too early or too late.

If I use

collide("dynamic", x, y + 1)

or

collide("dynamic", x, y + 2)

then it hits too late.

if I use

collide("dynamic", x, y + 3)

then it hits too early.

However to hit the ground, I use

collide("ground", x, y + 1)

so why shouldn’t

collide("dynamic", x, y + 1)

work? Why does it still hit too late even if I up the number to 2? It doesn’t even hit a bit earlier, it hits the exact same spot as +1, it’s as if +1 or +2 doesn’t make a difference, only when I set it to +3, then it actually changes (but then it’s too much).

TL; DR

collide(“dynamic”, x, y + 0, 1 or 2) = rain drop hits 2 pixels BELOW the dynamic block, collide(“dynamic”, x, y + 3) = rain drop hits 2 pixels ABOVE the dynamic block,


(Martí Angelats i Ribera) #2

It’s hard to say without watching the code but here i let you some ideas:

  1. Probably the error is in the dynamic type class mask (if it works well in the wround it should in the dynamic)
  2. Try using colidePoint.
  3. Create another class and test what happens.
  4. Look at the erther of the updates. Maybe it colides becouse the block was there but then it moves.

I hope it will help you even if it’s just a bit.


(Bora Kasap) #3

Main subject: Probably your raindrop speed is a little much for your raindrops’ heights.

Thats a classical way to solve this problem.

  • 1 - When collide event triggered

  • 2 - Set bottom position of the raindrop to top position of the ground block

  • 3 - trigger splash

And a second way

Requirements: A booleanX variable which is “false” in the beginning.

  • 1 - When collide event triggered by the collide function which you added offset for collision position by “+3” pixels

  • 2 - set booleanX = true

And thats the lines you need in update() function for second way

var precision:int = 2;
if (booleanX == true) {
     for (var i:int = 0; i < precision; i++) {
        y += raindropYspeed/precision;
        if(collide("dynamic", x, y)) splash();
   } 
} else if(collide("dynamic", x, y, +3)) booleanX = true;

so, all about increasing collision precision for the last moments of the raindrop


(Mike Evmm) #4

Or why not use moveBy() and moveCollideX/Y()?