How to move up and down a ladder in a platform game
i creating platform game , want move , down ladders. had created previous post creating elevators @ http://forums.adobe.com/message/5974173#5974173
i cannot movement , down ladders right. have far calculating height of ladder , move character vertical using hero.y coordinates. not smooth , jerky. need have character move in smooth motion , down ladder. not sure doing wrong?
here screenshot of ladder. 113.3 pixels in height.
here code have far:
public function keydownfunction(event:keyboardevent)
{
// don't move until in play mode
if (gamemode != "play") return;
if (event.keycode == 38) // 38 keycode arrow
{
hero.moveup = true;
}
if (event.keycode == 40) // 40 keycode down arrow
{
hero.movedown = true;
}
if (event.keycode == 37) // 37 keycode left arrow
{
//trace("push left");
hero.moveleft = true;
}
else if (event.keycode == 39) // 39 keycode right arrow
{
//trace("push right");
hero.moveright = true;
}
else if (event.keycode == 32) // 32 keycode spacebar
{
if (!hero.inair)
{
hero.jump = true;
}
}
}
public function checkcollisions()
{
for (var i:int = enemies.length-1;i >= 0; i--)
{
if (hero.mc.hittestobject(enemies[i].mc))
{
// hero jumping down onto enemy?
if (hero.inair && (hero.dy > 0))
{
enemydie(i);
}
else
{
herodie();
}
}
}
// items
for (i=otherobjects.length-1; i>=0;i--)
{
if (hero.mc.hittestobject(otherobjects[i]))
{
getobject(i);
}
}
// pit
for (i=evilobjects.length-1; i>=0; i--)
{
if (hero.mc.hittestobject(evilobjects[i]))
{
herodie();
}
}
// climb ladder
for (i=ladderobjects.length-1; i>=0; i--)
{
if (hero.mc.hittestobject(ladderobjects[i]))
{
//climbladder();
//trace(ladderobjects[i].y);
/*
if (hero.mc.y < ladderobjects[i].y-1)
{
hero.mc.y -= 1;
}
*/
if (hero.moveup)
{
for (var h:int = 0; h < (ladderobjects[i].height-1); h++)
{
hero.mc.y -= 1;
}
}
}
}
}
my thought use checkcollisions() function. code uses following conditional operations:
1. hero touching ladder?
2. player pushing arrow on keyboard? if so, move hero.y height of ladder mc.
what can fix make hero move smoothly? also, had move ladder down when hero standing on ledge above ladder hero not touch ladder mc. have coding error makes hero not able jump when touching it. same inability jump happens if hero touching elevator or spring.
thanks,
alex
More discussions in ActionScript 3
adobe
Comments
Post a Comment