Hittest error - not the usual stuff, it's a tricky one!

Subscribe to Hittest error - not the usual stuff, it's a tricky one! 7 posts

avatar for TAKERONE TAKERONE 2 posts
Flag Post

Hi guys,

I’ve been developing flash since years, I don’t think myself as a big deal as a developer (though I work as one at a multinational company). It’s only AS2.
The fact is that I have NEVER EVER wrote to a forum with any problem, I could solve everything I wanted to, but this time I don’t have the slightest idea about , and can’t find out what the problem is, and it’s driving me nuts. Maybe someone saw this error before, and can help me. Here is it:

http://takerone.com/hittest/

Platform instances on the stage push their paths (their “this”) into an array automatically, then I “onEnterFrame” check if the character’s hittest MC (red) hits the said platform instances’ hittest MC (blue) (iterating through the array). It should be pretty straightforward, usually it works. But sometimes they doesn’t hit when they should, and I have no idea why.

Here is the source: http://takerone.com/hittest/test.fla (CS5.5)

Any idea would be greatly appreciated!

 
avatar for pl0xz0rz pl0xz0rz 33 posts
Flag Post

You’re doing a dicrete collision check. Try using a raycast from last known good coordinates to current ones, and then it should work.

It takes some math, but nothing difficult.

EDIT; Or just icrease the height of the hitboxes

 
avatar for ArreatsChozen ArreatsChozen 85 posts
Flag Post

Yup, what pl0xz0rz said. I actually read an article about it just the other day. Pretty common platformer problem.

Your characters move in discrete frames (giving the illusion of fluid movement). The problem is if the players hitbox happens to move completely past the object in questions hitbox, there will be no collision detected.

A few things you can do to solve it:
– increase tick speed (keeping relative acceleration/ velocity the same). This gives your boxes more frames in which to collide in
– increase the size of the hitbox. This makes it easier for a collision to take place
– impose a maximum velocity on your characters. If you have a maximum velocity, you can calculate the maximum possible distance able to be traveled in 1 frame. With this information you can give your hitboxes appropriate sizes to guarantee a collision.
– ray casting method as described above (although rather an overkill for your game)

All but the ray casting are trivial to implement. Good luck.

 
avatar for DrYoshiyahu DrYoshiyahu 678 posts
Flag Post

In case you didn’t get that: Red is moving so fast that on one frame it’s above blue, and the next frame, it’s below it. There’s no frame in the middle where red was touching blue.

 
avatar for feartehstickman feartehstickman 521 posts
Flag Post

You could follow a similar approach to how Trials handles fast moving objects.

Have a way of identifying objects that have the potential to move fast.
Only check the object with advanced collision detection if it is moving above a certain speed where you have calculated that it could pass through an object undetected.

So like if(object.fastMoving)if(object.vel>=4)advancedCollisionCheck…

 
avatar for Frostyfun Frostyfun 2 posts
Flag Post

really simple
if hittest wont work dont use hittest

for loop through all the platforms then see if one is going to be at or above the y coordinate hes gonna land on with the same x value

if it is stop him at that platforms y

 
avatar for TAKERONE TAKERONE 2 posts
Flag Post

Hi guys!

Thank you very much for all the answers, first of all to pl0xz0rz, I don’t know how I didn’t think of making the hitboxes bigger, that time it just didn’t seem logical, now I understand what the problem was and obviously could correct it out. (And raycasting looks an interesting thing too, though I agree with ArreatsChozen in that it would have been an overkill for this problem, but nonetheless I have read and will read after this stuff too) So I made my correnctions to my program already after pl0x0rz’s comment, I just didn’t write in here because I wanted to see if other people have any different ideas I can learn from, for example I really like and memorize Frostyfun’s solution which probably wouldn’t be written if I already had said that I was through my problem :-) So once again thank to all of you who have answered, and I hope your answers helped and will help to people other than me as well!

Have a nice and happy new year all!

Taker