Gravity

Whats wrong with this?

Put this in your characters mc:

[AS]
//Sets the properties
onClipEvent (load) {
gravity = 1.5;
velocity = 0;
falling = true;
stop();
speed = 7;
}
//Basic control with gravity
onClipEvent (enterFrame) {
if (this._x<-2) {
this._x = 777;
}
if (this._x>781) {
this._x = 2;
}
if (Key.isDown(Key.LEFT)) {
this.gotoAndStop(1);
_x -= 5.5;
}
if (Key.isDown(Key.RIGHT)) {
this.gotoAndStop(2);
_x += 5.5;
}
if (falling == true) {
velocity += gravity;
_y += velocity;
}
//This allows you to have platforms
if (this.hitTest(platform)) {
if (falling == true) {
_y = platform._y;
velocity = 0;
falling = false;
_y += velocity;
}
} else {
falling = true;
}
// Allows duplication of platforms
for (i=0; i<99; i++) {
if (this.hitTest("_root.platform"+i)) {
platform = eval("_root.platform"+i);
}
// Jumping, change the velocity number
// to set the height of your jump
if (Key.isDown(Key.UP)) {
if (falling == false) {
velocity -= 15;
falling = true;
}
}
}
}
[/AS]

  1. Create a platform and call it platform

  2. It doesnt work… why…