Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am making a super mario game in flash. I just started working on the collision but I met a problem whenever I step on the top corner of my wal. In super mario, when you step on the blocks, you will stay there, right. That is my exact problem in my game, it won't step there instead it won't collide :(

Okay, first, I made an object converted to a symbol with the instance name of "character". Then I made another object, a long block I named "wall". I went to the character object and placed this code to handle the left and right collision.

onClipEvent(enterFrame) {
//this handles the right collision
if (Key.isDown(Key.RIGHT)) {
    //handles the collision with the wall (instance name of the wall obstacle)
    if(this.hitTest(_root.wall)) {
        this._x+= 7;
    }

}
//this handles the left collision
if (Key.isDown(Key.LEFT)) {
    //handles the collision with the wall (instance name of the wal obstacle
    if (this.hitTest(_root.wall)) {
        this._x+= -7;
    }
}
}

On this code, I only made the collision with the left and right side of the wall. How about if I want to make the ones in the top so Mario would step on the wall at the top?

share|improve this question
A cheap solution is to simply check the angle between the two colliding objects and determine if its "from above". Another technique is having 4 collision boxes to an object and check which hit. The more complicated solutions are well more complicated and if you need those check out some premade tools like box2d(exported to many different languages). – dennmat Feb 8 at 0:37
Have you coded for "jump"... and "gravity" ? Because these 2 things are important to code for, before you go to code for making it stay on the top of the wall. The logic is too stop the effect of "gravity" , once the Mario hits the top corner of the wall. – Vishwas Gagrani Feb 8 at 6:04

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.