This one really stumped me. I got the following code out of a tutorial on www.bit-101.com. If you read it you can see that the creature is Mouse Responsive but I need it to be * Key Responsive * so do you have any ideas, I tried having a var for the speed and changin that var on key press of a button. but that did continual motion in one direction until I pressed the right or left to then change the direction. So here is the code.
[AS]
leg = 50;
legHeight = 20;
numFeet = 6;
grav = .5;
k = .2;
damp = .9;
bottom = 380;
createEmptyMovieClip(“legs”, 0);
body_mc.swapDepths(1);
for (i = 0; i < numFeet; i++)
{
foot = attachMovie(“foot”, “f” + i, i+2);
foot.angle = Math.PI * 2 / numFeet * i;
foot._x=body_mc._x;
foot._y=body_mc._y;
}
body_mc.onEnterFrame = function()
{
speed=(_xmouse-270)*.0005;
this.angle+=speed;
for (i = 0; i < numFeet; i++)
{
walk(_root[“f” + i]);
}
this.vy += grav;
this.vx *= damp;
this.vy *= damp;
this._x += this.vx;
this._y += this.vy;
legs.clear();
legs.lineStyle(1,0,100);
for(i=0;i<numFeet;i++)
{
var foot=_root[“f”+i];
legs.moveTo(foot._x, foot._y);
legs.curveTo(foot._x, body_mc._y, body_mc._x, body_mc._y);
}
};
function walk(foot)
{
var totalAngle = body_mc.angle + foot.angle;
var tx = body_mc._x + Math.cos(totalAngle) * leg;
var ty = body_mc._y + Math.sin(totalAngle) * leg + legHeight;
var ax = (tx - foot._x) * k;
var ay = (ty - foot._y) * k;
foot.vx += ax * .8;
foot.vy += ay * .8;
body_mc.vx -= ax * .2;
body_mc.vy -= ay * .2;
foot.vy += grav;
foot.vx *= damp;
foot.vy *= damp;
foot._x += foot.vx;
foot._y += foot.vy;
if (foot._y > bottom)
{
foot._y = bottom;
foot.vx = 0;
foot.vy = 0;
}
if(foot._x>520)
{
foot._x=520;
foot.vx=0;
foot.vy=0;
foot._rotation=-90;
}
else
{
foot._rotation=0;
}
}
[/AS]