Hey, I figured this would be a popular subject, so i did search the forums, but didn’t find anything relevent to my point. Whether I can search correctly, I’m sure i’ll be corrected on
Anyway, I’m a novice at AS, but I want to create a platformer (don’t worry! I’m not going to ask you lot to do it!), just for fun + practice. It’ll be Mario-esque, just for the lack of creativity needed to create it.
I can handle all the controls and DuplicateMovieClip() etc. It’s the hitTest + gravity i’m worried about. Here is an example of my hitTests:
onClipEvent (load) {
speed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (this.hitTest(_root.wall_left)) {
_x += speed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
if (this.hitTest(_root.wall_right)) {
_x -= speed;
}
if (Key.isDown(Key.UP)) {
_y -= speed;
}
if (this.hitTest(_root.wall_up)) {
_y += speed;
}
if (Key.isDown(Key.DOWN)) {
_y += speed;
}
if (this.hitTest(_root.wall_down)) {
_y -= speed;
}
}
/*wall_up,down,left,right are instance names of a
movieclip called wall which is on the stage 4 times.
Boundries, wall_up at the top of the stage, etc.*/
Which is all very simple, but it works, so it’s been fine for me.
When I introduce gravity (which I need help with, but will get onto in a moment), The character won’t fall with an even pace, so i wont be able to counter the speed as I have done in the code above.
Is there a more technical way of using hitTests to stop a character?
And how would I implement gravity (I have searched and read the forums, and read Poms tutorial but im still not sure) into a game, such as a 2D platformer?