0
votes

So I created my own code for a 2d platform game (like Mario). I decided to use the hitTestPoint method to handle my collisions. It worked smooth as butter, and everything was working perfectly. The character could move up and down ramps perfectly. My next step in creating my game would be to change my character (which was a block at the time) into a human character that can go to frames labeled "walk", "jump" and "stand". After creating variables for the two character states "run" and "stand" I coded the character to go to frame label "run" if the left or right keys are down, and "stand" if the character is not running, jumping or falling. Then the code was working okay, but there were quite a few problems that were occurring such as the character randomly running through walls and teleporting up ramps. I still have both versions (working and glitched). Other than the character movie clip changing frames, the code was not altered. I have absolutely no idea why the character is acting like this now. If anyone has experienced a problem like this before or knows what the problem behind this is, please help me out!

Drake Swartzy

2

2 Answers

2
votes

It's very likely your samples are not frequent enough (with the implementation you're using) to detect a collision.

enter image description here

With a low enough frequency, you'll update the position of your character, and then test whether it's overlapping the target. This means (if you're going fast enough) you could completely miss the collision.

A better approach may to use raycasting. See How do I handle collision detection so fast objects are not allowed to pass through walls?

0
votes

Thanks so much for the help Atriace! Sorry, I actually just discovered the problem.... The code was glitching up because when I changed the scaleX value of the character (when the character turned directions), it also effected the points which were nested within the character. These points were used to handle character collisions. Thus that's why the character was acting strangely when it came to X values. However, your answer was definitely a possibility in a situation like this. Once again, thank you for the help.

Cheers, Drake Swartzy