Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-16-2012, 07:49 PM   #1
stephengamage
Registered User
 
Join Date: May 2012
Posts: 2
Default [AS2] My character falls through the ground

My character just falls through the ground in my game, the floor is the base, and block 13 is about four platforms (all one symbol). Below is my code, it's directly in the movie clip. I'm using AS2. Any help appreciated, thanks.

Below is my code/script:

ActionScript Code:
// Stephen Gamage onClipEvent(load){     speed = 7;     jumpspeed =  7;     gravity = 0;     gravityfaster = 0.3;     jumping  = false; } onClipEvent(enterFrame){     if(Key.isDown(Key.LEFT)){         this._x -= speed;     }     if(Key.isDown(Key.RIGHT)){         this._x += speed;     }     if(Key.isDown(Key.SPACE)){         jumping = true;     }     if(jumping){         this._y -= jumpspeed;     }     gravity += gravityfaster;     this._y += gravity;     if(this.hitTest(_root.floor1)){         this._y -= gravity;         gravity = 0;         jumping = false;     }         /*The code below flips the character either     left or right depending on which key is down.     */         if(Key.isDown(Key.LEFT)){         gotoAndStop("right");     }     if(Key.isDown(Key.RIGHT)){         gotoAndStop("left");     } }

Thanks
stephengamage is offline   Reply With Quote
Old 05-20-2012, 10:33 PM   #2
dialectric
Senior Member
 
dialectric's Avatar
 
Join Date: May 2006
Location: USA
Posts: 614
Default

Hi,

Falling through the floor should be prevented by a hittest; it looks like you try to do that here:

if(this.hitTest(_root.floor1)){
this._y -= gravity;
gravity = 0;
jumping = false;
}

try


if(this.hitTest(_root.floor1)){
trace ("the floor hittest works");
//this._y -= gravity; //you don't need this line.
//there will be no change in y if the hittest returns true
gravity = 0;
jumping = false;
}

- dialectric
dialectric is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:02 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.