PDA

View Full Version : [AS1] Character Movement Help


SoreSkater
09-07-2003, 12:14 AM
can someone plz gimme a code for a character movement...and how to make the movieclips...i made a code and it got all screwed up and it just wouldnt work the way i wanted so i gave up and im asking you ppl...anyway...i want my character to have a standing motion wen no buttons are pressed, a left and right facing movement, and a jumping motion...no collision of a ground or wall needed...please

annexion
09-07-2003, 12:30 AM
If you would just search this forum you would undoubtedly find the exact code you were looking for. If that doesn't yield you the results I would suggest searching the movies section.

Good luck.

SoreSkater
09-07-2003, 12:37 AM
Heres the code that ive been working wit...

onClipEvent (load) {
move = 0;
lock = true;
}
onClipEvent (keyDown) {
this.mario.play();
}
onClipEvent (keyUp) {
this.mario.gotoAndStop(1);
}
onClipEvent (enterFrame) {
if (move == 0) {
if (lock) {
this._x += Xstep;
Ystep = 0;
Xstep = 0;
if (Key.isDown(Key.LEFT)) {
Xstep = -10;
Ystep = 0;
this.gotoAndStop("left");
} else if (Key.isDown(Key.RIGHT)) {
Xstep = 10;
Ystep = 0;
this.gotoAndStop("right");
}
}
}
}
onClipEvent (enterFrame) {
render();
}




i just wanna know how to make the character jump and stay do a standing motion wen keys are up.

Adrenaline
09-07-2003, 02:46 AM
Did you not search the forums like annexion said?? I did and check out what I came up with:
http://www.actionscript.org/forums/search.php3?s=&action=showresults&searchid=1141081&sortby=lastpost&sortorder=descending

Chrono Paradox
01-12-2009, 02:07 PM
Heres the code that ive been working wit...

onClipEvent (load) {
move = 0;
lock = true;
}
onClipEvent (keyDown) {
this.mario.play();
}
onClipEvent (keyUp) {
this.mario.gotoAndStop(1);
}
onClipEvent (enterFrame) {
if (move == 0) {
if (lock) {
this._x += Xstep;
Ystep = 0;
Xstep = 0;
if (Key.isDown(Key.LEFT)) {
Xstep = -10;
Ystep = 0;
this.gotoAndStop("left");
} else if (Key.isDown(Key.RIGHT)) {
Xstep = 10;
Ystep = 0;
this.gotoAndStop("right");
}
}
}
}
onClipEvent (enterFrame) {
render();
}




i just wanna know how to make the character jump and stay do a standing motion wen keys are up.
this should work with the gravity effect for jumping im not sure how to give you the standing MC(movie clip) though sorry:

//FLOORED OBJECT FOR GAME
//Keeps a MC on a defined floor, simple use for building
//platform jump'n'run games.
//usage:
//this.keepOnFloor(gravity,floor)
//e.g. this.keepOnFloor(7,_root.ground);

Movieclip.prototype.keepOnFloor=function (gr,floor) {
this._y+=this._gravity+=gr;
var pos=new Object();
pos.x=this._x; pos.y=this._y;
for (var i=0; i<=this._gravity; i++) {
if (floor.hitTest(pos.x,pos.y-i,1)) {
while (floor.hitTest(pos.x,pos.y- i,1)) {
pos.y--;
}
this._y=pos.y- i;
this._gravity=0;
}
}
}
//usage
//Draw any shape that shall be your floor and convert it to
//a Movieclip. Name this MC e.g. "ground".

//Put this on your character:
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {this._x+=10;}
if (Key.isDown(Key.LEFT)) {this._x-=10;}
if (Key.isDown(Key.UP)&& this._gravity == 0{
this._gravity=-50; // JUMP!


}

this.keepOnFloor(7,_root.ground 2);
}

rrh
01-12-2009, 08:20 PM
Does 'move' ever become a value other than '0' ?
Does 'lock' ever become a value other than 'true' ?

If your code isn't working the way you want, the first step is to figure out what way it is working.