I'm creating 2D platformer game. I'm having an issues with my collisions. When my character hits is standing on top of a platform it will stay there for 2.5 seconds then fall through all other platforms to the ground floor. I think it has to do something with my gravity function and collision function not working together properly. I really can't figure this out any help would be appreciated.
this = fireboy1
Here's gravity code from my character class:
public var gravity:int = 0;
public var floor:int = 461;
public function adjust():void
{
//applying gravity
this.y += gravity;
if(this.y + this.height <floor)
gravity++;
else
{
gravity = 0;
this.y = floor - this.height;
}
and here is the code for my collisions from the main class:
//collision detection of platform1
public function platform1Collision():void
{
if(fireboy1.hitTestObject(Platform1))
{
if(fireboy1.y > Platform1.y)
{
fireboy1.y = Platform1.y + Platform1.height;
}
else
{
fireboy1.y = Platform1.y - fireboy1.height;
}
}