ForumsProgramming ForumCharacter movement

16 6381
harveygames
offline
harveygames
10 posts
Nomad

Well im making my own game just to see if I am capable to do this.
Anyways, i have created a stick man and put it in a movie clip where he can run
and i used action script... very basic

which can make him move left or right and even up.... The thing is he can run out and when i stop he doesnt stop... He runs on the spot...

So i made another movie clip... This time hes still... and I made my running person on a different frame... But its just like hes stopped but moving side to side...
heres that code


I want i can recall animations on different frames so he can jump, kick, punch, stop, and run... Can someone help me???

<br>onClipEvent (load) {<br>	speed = 10;<br>}<br>onClipEvent (enterFrame) {<br>	if (Key.isDown(Key.RIGHT)) {<br>		_x += speed;<br>	}<br>	if (Key.isDown(Key.LEFT)) {<br>		_x -= speed;<br>	}<br>	if (Key.isDown(Key.SPACE)) {<br>		_y -= speed;<br>	}<br>}<br>
  • 16 Replies
harveygames
offline
harveygames
10 posts
Nomad

its gotoAndPlay("Title", 4);
but it still doesnt do anything both things

manny6574
offline
manny6574
922 posts
Nomad

is the running on the main or movie clip time line?

manny6574
offline
manny6574
922 posts
Nomad

if its on the movie clip line then:

onClipEvent (load) {
speed = 10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_root.whateverthemovieclipiscalled'gotoAndPlay(running);
_x += speed;
}
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.SPACE)) {
_y -= speed;
}
}

im not sure it'll work but you can try

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

Do something like:

if(!Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.SPACE))
{
_root.character.gotoAndStop(1);
}



the ! before the code means the opposite, so it's testing if all three keys aren't pressed, goto the first frame on your character's movieClip.

harveygames
offline
harveygames
10 posts
Nomad

its like this...
I added a movie clip
Where he does all his run animation
then i put it in a different scene on frame 4

Then i added another movie clip this time hes stopped but how do i make it so i can recall the one where he is running on the first scene frame 4

harveygames
offline
harveygames
10 posts
Nomad

AbnormalIdiot, i tried doing the thing u said... where it stops on the selected frame on the character... But it doesn't stop... It like still runs on the stop...


onClipEvent (load) {
speed = 10;
}
onClipEvent (enterFrame) {
if (!Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.SPACE)) {
_root.character.gotoAndStop(1);
} else {
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.SPACE)) {
_y -= speed;
}
}
}

but it still doesnt work

harveygames
offline
harveygames
10 posts
Nomad

Well... I got him to stop by giving my movie clip an instance name ... But now he doesnt run...
Heres the code..



onClipEvent (load) {
speed = 10;
}
onClipEvent (enterFrame) {
if (!Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.SPACE)) {
_root.character.gotoAndStop(1);
} else {
if(Key.isDown(Key.RIGHT)){
_root.character.gotoAndPlay(1);
_x+=speed;
}
if(Key.isDown(Key.LEFT)){
_root.character.gotoAndPlay(1);
_x-=speed;
}
if(Key.isDown(Key.SPACE)){
_y-=speed;
}
}
}

harveygames
offline
harveygames
10 posts
Nomad

and just to tell you guys... im not writing the action script within the movie clip...
i just clicked the movie clip and started writing the action script with in the timeline...

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

It's because you're telling the character to goto the frame with him standing still, and you probably have a stop command in that frame. Try _root.character.gotoAndPlay(2);

harveygames
offline
harveygames
10 posts
Nomad

i dont have a stop in there
and i tried it with gotoandplay2 and it still doesnt work...
i've been trying to work with it
and i got him to turn left and right and jump
heres the stuff

Anyways i have a movie clip which has 4 frames
Those 4 frames are used to show my guy running

the thing is when i stop controlling him... its like hes running on the spot... how do i make it so he stops... and i also want to know how to make him sorda do a run jump...
I have the jump part but its like he runs in the air and also... if i hold down the jump button its like he on a rocket... he keeps going up untill i let go...

heres my code
<code>
onClipEvent (load) {
speed = 10;
isjumping = false;
jumpspeed = 0;
startY = _y;
}
onClipEvent (enterFrame) {
if(isjumping) {
_y += jumpspeed;
jumpspeed +=1;
if(_y>+startY) {
_y = startY;
isjumping = false;
}
}
if(Key.isDown(Key.RIGHT)) {
_x+=speed;
_xscale=100;
_root.character.gotoAndPlay(1);
} else {
_root.character.gotoAndStop(1);
}
if(Key.isDown(Key.LEFT)) {
_x-=speed;
_xscale=-100;
_root.character.gotoAndPlay(1);
} else {
_root.character.gotoAndStop(1);
}
if(Key.isDown(Key.SPACE)) {
isjumping = true;
jumpspeed = -5;
}

}</code>

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

Oh, my mistake, I misunderstood. For the jumping problem, you need to slowly decrease jumpspeed, and have it start at, say, 30. Each frame after _y -= jumpspeed; add jumpspeed -= 0.5 or something like that.

To make your character stop running in the air, add this inside the if commands for left and right: && !Key.isDown(Key.SPACE)


For the running thing, have your first frame be of the character standing still, and the 4 after that the running animation. On the last of the 4 running animation frames, use gotoAndPlay(2); And do something like:

if((!Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT)) or Key.isDown(Key.SPACE))
{
gotoAndStop(1);
}

For the running jump, add something like:
if(Key.isDown(Key.SPACE) && (Key.isDown(Key.RIGHT) or Key.isDown(Key.LEFT)))
{
_root.character.gotoAndStop(5); //or gotoAndPlay(5); but you need frame 5 to be/start the running jump animation.
}

harveygames
offline
harveygames
10 posts
Nomad

THANKS AlOT ABNORMAL!!!!!
This is what i did... on my first frame i put it stop(); where he would stay... and on my second frame.. i put a movie clip with in a movie clip and made it go to my running and its running and it STOPS!!!

harveygames
offline
harveygames
10 posts
Nomad

okay nvm... i still have a problem...
I have a movie clip
the first frame is my guy stopped
i put an stop action script in there

in my second frame... i added another movie clip
this time there is 6 frames with in that movie clip where he is supposed to run... the thing is it only shows 2 frames of the 6....
Heres the code for my character


onClipEvent (load) {
speed = 10;
isjumping = false;
jumpspeed = 0;
startY = _y;
}
onClipEvent (enterFrame) {
if(isjumping) {
_y += jumpspeed;
jumpspeed +=1;
if(_y>+startY) {
_y = startY;
isjumping = false;
}
}
if(!Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.SPACE))
{
_root.character.gotoAndStop(1);
}
if(!Key.isDown(Key.LEFT) && Key.isDown(Key.RIGHT) && !Key.isDown(Key.SPACE))
{
_x+=speed;
_xscale=100;
_root.character.gotoAndPlay(2);
}
if(Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.SPACE))
{
_x-=speed;
_xscale=-100;
_root.character.gotoAndPlay(2);
}

}

harveygames
offline
harveygames
10 posts
Nomad

okay i did it... I erased the other idea... and put my running animation all in the first 5 frames and on the last frame i made it go back to frame 1... and on frame 6 i had him stopped and i put a stop command in there...
and i used
!KeyisDown(Key.LEFT) && !KeyisDown(Key.RIGHT)) {
_root.character.gotoAndStop(6);
}

And it worked

AbnormalIdiot
offline
AbnormalIdiot
110 posts
Nomad

Alright, glad I could help!

Showing 1-15 of 16