Be a Supporter!

Need Walking code!

  • 270 Views
  • 3 Replies
New Topic Respond to this Topic
TheFuzzy
TheFuzzy
  • Member since: Feb. 19, 2009
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Need Walking code! 2009-03-15 13:52:49 Reply

OK I have everything in my game complete but the walking code isn't working. I will give you the one I have and if you could fix it that would be great, but if you give me a new one that dose mostly the same thing that would be great too. The problem with the old one is that the screen scrolls faster then the person walks, and...

THANK YOU!

(The code I am using now)

onClipEvent (load) {
grav = 0;
speed = 4;
jumpHeight = 15;
scale = _xscale;
slowfall = .8;
}
onClipEvent (enterFrame) {
grav++;
_y += grav;
while (_root.ground.hitTest(_x, _y, true)) {
_y--;
grav = 0;
}
if (Key.isDown(68)) {
_x += speed;
_xscale = scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
} else if (Key.isDown(65)) {
_x -= speed;
_xscale = -scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
} else {
if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(79)) {
this.gotoAndStop(3);
}
}
if (Key.isDown(83)) {
grav *= slowfall;
}
if (Key.isDown(79) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68)) {
this.gotoAndStop(4);
}
if (Key.isDown(87) && _root.ground.hitTest(_x, _y+3, true)) {
grav = -jumpHeight;
_y -= 4;3
this.gotoAndStop(2);
}
if (_root.ground.hitTest(_x+(_width/2), _y-(_height/2), true) || _root.ground.hitTest(_x+(_width/2), _y-((_height/6)*4), true)) {
_x -= speed;
}
if (_root.ground.hitTest(_x-(_width/2), _y-(_height/2), true) || _root.ground.hitTest(_x-(_width/2), _y-((_height/6)*4), true)) {
_x += speed;
}
if (_root.ground.hitTest(_x, _y-_height, true)) {
grav = 2;
}
}


The Fuzzy - Visit my user page... ITS AWESOME!!!! (Click the picture)

BBS Signature
Zyphonee
Zyphonee
  • Member since: Nov. 13, 2008
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to Need Walking code! 2009-03-15 16:40:07 Reply

You obviously copy/pasted that code, since it is for gravity, not for movement, however, you might want to try this one out:

onClipEvent(load){
speed=5; stop(); dir=1;moving=0;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)){moving=1; dir=1;}
else if (Key.isDown(Key.DOWN)){moving=1; dir=2;}
else if (Key.isDown(Key.LEFT)){moving=1; dir=3;}
else if (Key.isDown(Key.UP)){moving=1; dir=4;}
else{moving=0;}
if(moving){
gotoAndStop(dir);
}else{
gotoAndStop(dir+4);
}
}
onClipEvent (enterFrame) {
_x+=Key.isDown(Key.RIGHT)*speed;
_x-=Key.isDown(Key.LEFT)*speed;
_y+=Key.isDown(Key.DOWN)*speed;
_y-=Key.isDown(Key.UP)*speed;
}

I actually wrote that one myself. Try to analize line by line.

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to Need Walking code! 2009-03-15 17:12:17 Reply

At 3/15/09 04:40 PM, Zyphonee wrote: I actually wrote that one myself.

Oh no you didn't (post 12)


- - Flash - Music - Images - -

BBS Signature
Zyphonee
Zyphonee
  • Member since: Nov. 13, 2008
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to Need Walking code! 2009-03-15 17:22:41 Reply

Yes, Mr. Denvish is right on that. I was silly enough as for posting that hybrid between two already written codes there, sorry!

Well, at least I hope it helped you!