# Gravity

**URL:** https://forum.kirupa.com/t/gravity/165391
**Category:** Uncategorized
**Created:** [October 10, 2005, 8:11pm UTC](https://forum.kirupa.com/t/gravity/165391 "2005-10-10T20:11:49Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![GPP](https://avatars.discourse-cdn.com/v4/letter/g/848f3c/32.png) [@GPP](https://forum.kirupa.com/u/GPP)
#### Post date: [October 10, 2005, 8:11pm UTC](https://forum.kirupa.com/t/gravity/165391/1 "2005-10-10T20:11:49Z")

</div>

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…
