Forum Topic: I've made a jumping engine for all.

(29,524 views • 373 replies)

This topic is 13 pages long. [ 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 91113 ]

<< < > >>
Happy

Rystic

Reply To Post Reply & Quote

Posted at: 7/23/04 10:31 PM

Rystic LIGHT LEVEL 50

Sign-Up: 03/09/02

Posts: 956

I've just made a new jumping engine. And, unlike all other jumping engines in this forum, this one doesn't have "_root.ground "in it. Infact, it has no required instance names other then "_root.circle" (which the object names itself as, so the user doesn't have to do anything). The advantage to this jumping engine is that you can have as many blocks for your character to land on as you want. And, it's so simple, even a n00b can use it without problems! Here it is:

Put this code in the character:

onClipEvent (load) {
fall = false;
_name = "circle";
jump = 0;
speed = 6;
jumpheight = 18;
maxfall = -54;
}
onClipEvent (enterFrame) {
xmin = getBounds(_root).xMin;
xmax = getBounds(_root).xMax;
ymin = getBounds(_root).yMin;
ymax = getBounds(_root).yMax;
if (Key.isDown(Key.SPACE) && fall == false && jump == undefined) {
fall = true;
jump = jumpheight;
}
if (jump<>undefined) {
if (jump>maxfall) {
jump--;
}
_y -= jump;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
}
------------------------------------
Put this code in any block:

onClipEvent (load) {
activated = false;
down = false;

}
onClipEvent (enterFrame) {
_root.report.text = Math.round(_root.circle.yMax)+" "+Math.round(yMin);
xmin = getBounds(_root).xMin;
xmax = getBounds(_root).xMax;
ymin = getBounds(_root).yMin;
ymax = getBounds(_root).yMax;
if (_root.circle.xMax>xMin && _root.circle.xMin<xMax && _root.circle.yMax<yMin) {
if (_root.circle.yMax-_root.circle.jump*2>yMin) {
_root.circle._y = ymin-_root.circle._height/2;
_root.circle.jump = undefined;
_root.circle.fall = false;
activated = true;
}
}
if (Math.round(_root.circle.yMax)>Math.round(yMin)) {
if (hitTest(_root.circle) && _root.circle.xmax<xmin) {
_root.circle._x -= _root.circle.speed;

---------------------------------------

That's IT! Now some of you may be even more interested in how I wrote this code. Well, here's some specs:

In itself, an object contains 6 properties:

(yMax + yMin)/2 = _y
yMax - yMin = _height
yMin - yMax = -_height
_height - yMax = -yMin
yMax - _height = yMin
yMin + _height = yMax

It can also be concluded that:

An object's size has no effect on it's _y value.
_height can never be a negative value, unlike _yscale.
yMin-yMax will always be negative, and yMax-yMin will always be positive.

---------------------------------

That's all for now. Now test my engine to see if it works. If so, gimmie some feedback.

Remember, you can use this to make multiple blocks, not just one called "_root.ground". BLOCKS DON'T NEED INSTANCE NAMES!

I really, really hope this works. It works fine for me.
}
if (hitTest(_root.circle) && _root.circle.xmin>xmax) {
_root.circle._x += _root.circle.speed;
}
if (hitTest(_root.circle) && _root.circle.ymin>ymax && _root.circle.jump>-1) {
_root.circle.jump = -1*(_root.circle.jump);
}
}
if (activated == true && not hitTest(_root.circle) && _root.circle.jump == undefined) {
_root.circle.jump = 0;
activated = false;
}
if (hitTest(_root.circle) && _root.circle.ymax>ymin && _root.circle.jump<>undefined && _root.circle._y<_y) {
_root.circle._y = ymin-_root.circle._height/2;
_root.circle.jump = undefined;
_root.circle.fall = false;
activated = true;
}
if (_root.circle.ymax-_root.circle.jump>ymin && _root.circle.xMin<xMax && _root.circle.xMax>xMin && _root.circle.jump<>undefined && _root.circle._y<_y) {
_root.circle._y = ymin-_root.circle._height/2;
_root.circle.jump = undefined;
_root.circle.fall = false;
activated = true;
}
}


None

Rystic

Reply To Post Reply & Quote

Posted at: 7/23/04 10:33 PM

Rystic LIGHT LEVEL 50

Sign-Up: 03/09/02

Posts: 956

AHHHHHHHHHHHHH! MISTAKE! THE BLOCK CODE IS ACTUALLY THIS:

onClipEvent (load) {
activated = false;
down = false;

}
onClipEvent (enterFrame) {
_root.report.text = Math.round(_root.circle.yMax)+" "+Math.round(yMin);
xmin = getBounds(_root).xMin;
xmax = getBounds(_root).xMax;
ymin = getBounds(_root).yMin;
ymax = getBounds(_root).yMax;
if (_root.circle.xMax>xMin && _root.circle.xMin<xMax && _root.circle.yMax<yMin) {
if (_root.circle.yMax-_root.circle.jump*2>yMin) {
_root.circle._y = ymin-_root.circle._height/2;
_root.circle.jump = undefined;
_root.circle.fall = false;
activated = true;
}
}
if (Math.round(_root.circle.yMax)>Math.round(yMin)) {
if (hitTest(_root.circle) && _root.circle.xmax<xmin) {
_root.circle._x -= _root.circle.speed;
}
if (hitTest(_root.circle) && _root.circle.xmin>xmax) {
_root.circle._x += _root.circle.speed;
}
if (hitTest(_root.circle) && _root.circle.ymin>ymax && _root.circle.jump>-1) {
_root.circle.jump = -1*(_root.circle.jump);
}
}
if (activated == true && not hitTest(_root.circle) && _root.circle.jump == undefined) {
_root.circle.jump = 0;
activated = false;
}
if (hitTest(_root.circle) && _root.circle.ymax>ymin && _root.circle.jump<>undefined && _root.circle._y<_y) {
_root.circle._y = ymin-_root.circle._height/2;
_root.circle.jump = undefined;
_root.circle.fall = false;
activated = true;
}
if (_root.circle.ymax-_root.circle.jump>ymin && _root.circle.xMin<xMax && _root.circle.xMax>xMin && _root.circle.jump<>undefined && _root.circle._y<_y) {
_root.circle._y = ymin-_root.circle._height/2;
_root.circle.jump = undefined;
_root.circle.fall = false;
activated = true;
}
}


None

Deathcon7

Reply To Post Reply & Quote

Posted at: 7/23/04 10:45 PM

Deathcon7 NEUTRAL LEVEL 21

Sign-Up: 10/01/03

Posts: 5,752

Nice job Rystic, n00bs are gonna flood the portal with side scrolling platformers. lol, it's an awesome code man.


None

Rystic

Reply To Post Reply & Quote

Posted at: 7/23/04 10:47 PM

Rystic LIGHT LEVEL 50

Sign-Up: 03/09/02

Posts: 956

At 7/23/04 10:45 PM, Deathcon7 wrote: Nice job Rystic, n00bs are gonna flood the portal with side scrolling platformers. lol, it's an awesome code man.

thnx... it was hard to make.. but i did it...


None

Taylor

Reply To Post Reply & Quote

Posted at: 7/23/04 11:57 PM

Taylor LIGHT LEVEL 09

Sign-Up: 08/19/03

Posts: 8,508

heres a platformer script (WITH SCROLLING (cool looking) JUMPING KICKING and much more)

character//

onClipEvent (load) {
down = false;
}
onClipEvent (enterFrame) {
if (Key.isDown(17) && !down) {
this.gotoAndPlay("kick");
down = true;
}
if (!Key.isDown(17)) {
down = false;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(65) && !down) {
this.gotoAndPlay("kick");
down = true;
}
if (!Key.isDown(65)) {
down = false;
}
}
onClipEvent (enterFrame) {
if (_root.move == true) {
this._x += _root.moveSpeedR;
this._x -= _root.moveSpeedL;
}
if (Key.isDown(Key.LEFT)) {
_root.moveSpeedL += .5;
}
if (Key.isDown(Key.RIGHT)) {
_root.moveSpeedR += .5;
}
}
onClipEvent(enterFrame) {
if(this._x >= 300) {
_root.scrollR = true;
} else {
_root.move == true;
}
}
onClipEvent(enterFrame) {
if(this._x >= 100) {
_root.scrollL = true;
} else {
_root.move = true;
}
}

onClipEvent (enterFrame) {
if (_root.health == 5) {
_root.health.gotoAndPlay(1)
}

if (_root.health == 4) {
_root.health.gotoAndPlay(2)
}
if (_root.health == 3) {
_root.health.gotoAndPlay(3)
}
if (_root.health == 2) {
_root.health.gotoAndPlay(4)
}
if (_root.health == 1) {
_root.health.gotoAndPlay(5)
}
}

for the platforms (name them plat1, plat2, plat3 ect//

onClipEvent (enterFrame) {

if (this.hitTest (_root.Player.bottomfeet))
{
_root.falling = false;
_root.hit1 = true;
}
else
{
_root.hit1 = false;
}

}

for the scrolling, select all the background items (PLATFORMS INANIMATE OBJECTS ECT) and turn them into an MC, named "ground"
and put this code on the mc named groudn//

onClipEvent(enterFrame) {
if(_root.scrollR == true) {
this._x -= _root.moveSpeedR/3;
_root.move = false;
}
if(_root.scrollL == true) {
this._x += _root.moveSpeedL/6;
}
}


None

MidnyteRayne

Reply To Post Reply & Quote

Posted at: 7/24/04 12:23 AM

MidnyteRayne DARK LEVEL 14

Sign-Up: 07/15/04

Posts: 13,108

hmm this is wierd because when I tested this code out ( i made a stick man and two little platforms) and i made the guy and the platforms MC's but when I add the code and check my syntaxes it has errors and says that onClipEvent can only be used in movie clip instances. So what could I have done wrong? Everything IS a MC


None

Rystic

Reply To Post Reply & Quote

Posted at: 7/24/04 07:07 AM

Rystic LIGHT LEVEL 50

Sign-Up: 03/09/02

Posts: 956

At 7/23/04 11:57 PM, PillowBiter wrote: heres a platformer script (WITH SCROLLING (cool looking)

You miss the point of this. There aren't suppose to be clip names. That way, you can make as many blocks as you like, not just one called ground.


None

Rystic

Reply To Post Reply & Quote

Posted at: 7/24/04 07:09 AM

Rystic LIGHT LEVEL 50

Sign-Up: 03/09/02

Posts: 956

At 7/24/04 12:23 AM, t4int3d_s0ul wrote: hmm this is wierd because when I tested this code out ( i made a stick man and two little platforms) and i made the guy and the platforms MC's but when I add the code and check my syntaxes it has errors and says that onClipEvent can only be used in movie clip instances. So what could I have done wrong? Everything IS a MC

I posted the wrong block code. Check out my second post in this thread to see the correction. Also, make sure these are in two seperate movie clips.


Happy

cuber3

Reply To Post Reply & Quote

Posted at: 7/24/04 07:37 AM

cuber3 NEUTRAL LEVEL 16

Sign-Up: 04/02/04

Posts: 312

Thanks Rystic ! ! !
I was making a platform game before, but when i made multiple platforms, the character sometimes fell through. In combination with some hittests, your code is superior !
Thanks again i'm really really glad this finally works !!


None

Mazza

Reply To Post Reply & Quote

Posted at: 7/24/04 08:11 AM

Mazza LIGHT LEVEL 35

Sign-Up: 02/10/02

Posts: 5,875

That's a great code! Maybe now my games won't suck as much anymore.


None

molkman

Reply To Post Reply & Quote

Posted at: 7/24/04 08:32 AM

molkman NEUTRAL LEVEL 08

Sign-Up: 03/12/04

Posts: 284

ooooh guys... looks difficult^^


None

Rystic

Reply To Post Reply & Quote

Posted at: 7/24/04 09:26 AM

Rystic LIGHT LEVEL 50

Sign-Up: 03/09/02

Posts: 956

At 7/24/04 07:37 AM, cuber3 wrote: Thanks Rystic ! ! !
I was making a platform game before, but when i made multiple platforms, the character sometimes fell through. In combination with some hittests, your code is superior !
Thanks again i'm really really glad this finally works !!

No problem, man. I've worked on perfecting this jump engine for awhile, and I'm glad I can finally share it with the NG community.


None

Rystic

Reply To Post Reply & Quote

Posted at: 7/24/04 09:27 AM

Rystic LIGHT LEVEL 50

Sign-Up: 03/09/02

Posts: 956

At 7/24/04 08:32 AM, molkman wrote: ooooh guys... looks difficult^^

Don't worry... I made it so simple, even a newbie can use it. No instance name requirements. Isn't that great?


None

adit-ya-sharma

Reply To Post Reply & Quote

Posted at: 7/24/04 09:33 AM

adit-ya-sharma NEUTRAL LEVEL 02

Sign-Up: 04/11/04

Posts: 269

Nice work man. Looks like a lot of hard work had been put in. But I go for art based collision detection.


None

GeoffCLogan

Reply To Post Reply & Quote

Posted at: 7/24/04 10:15 AM

GeoffCLogan LIGHT LEVEL 11

Sign-Up: 04/25/04

Posts: 4,424

Looks nice, for some reason I'm too much of a moron to get it to work :D. But it's possible to create a platformer with having instance names......


None

schorhr

Reply To Post Reply & Quote

Posted at: 7/24/04 10:52 AM

schorhr NEUTRAL LEVEL 11

Sign-Up: 05/28/02

Posts: 9,029

If i jump onto the same block again, my MC falls right through it. I am using the second code part..


None

Ercle

Reply To Post Reply & Quote

Posted at: 7/24/04 10:52 AM

Ercle LIGHT LEVEL 07

Sign-Up: 01/07/04

Posts: 65

eerr...i tryed useing this and all the charictor does is jump....not when u press a button, but constantly...what am i doing wrong?


None

schorhr

Reply To Post Reply & Quote

Posted at: 7/24/04 10:53 AM

schorhr NEUTRAL LEVEL 11

Sign-Up: 05/28/02

Posts: 9,029

Jumping works fine here?


None

schorhr

Reply To Post Reply & Quote

Posted at: 7/24/04 11:16 AM

schorhr NEUTRAL LEVEL 11

Sign-Up: 05/28/02

Posts: 9,029

I'dd prefer something like my rogerjump game, or www.di-m.de/runner.swf :-) Still i find it a great Idea that you made this code which does not require any naming, so every beginner can use it... Though I still dont get why i am falling through a block unless i jump on a different one first.


None

Taylor

Reply To Post Reply & Quote

Posted at: 7/24/04 01:24 PM

Taylor LIGHT LEVEL 09

Sign-Up: 08/19/03

Posts: 8,508

At 7/24/04 07:07 AM, Rystic wrote:
At 7/23/04 11:57 PM, PillowBiter wrote: heres a platformer script (WITH SCROLLING (cool looking)

i posted the wrong thing, sorry

You miss the point of this. There aren't suppose to be clip names. That way, you can make as many blocks as you like, not just one called ground.

I KNOW>>>I POSTED THE WRONG SCRIPT


None

Rystic

Reply To Post Reply & Quote

Posted at: 7/24/04 02:13 PM

Rystic LIGHT LEVEL 50

Sign-Up: 03/09/02

Posts: 956

At 7/24/04 10:52 AM, schorhr wrote: If i jump onto the same block again, my MC falls right through it. I am using the second code part..

Hmmm... that doesn't make sense. E-mail your FLA to me (if you want) and I'll take a look at it.

Also, this would be a good time to address anyone who wants to modify the code: you are allowed to, but e-mail me first and tell me what your updating.

Rystic_Force@hotmail.com


None

Rystic

Reply To Post Reply & Quote

Posted at: 7/24/04 02:14 PM

Rystic LIGHT LEVEL 50

Sign-Up: 03/09/02

Posts: 956

At 7/24/04 10:52 AM, -Ercle- wrote: eerr...i tryed useing this and all the charictor does is jump....not when u press a button, but constantly...what am i doing wrong?

I don't know why people are having problems. I tested this code over and over. Tell me, are you using movie clips AND the correct code?


None

Rystic

Reply To Post Reply & Quote

Posted at: 7/24/04 02:17 PM

Rystic LIGHT LEVEL 50

Sign-Up: 03/09/02

Posts: 956

ANYONE WHO HAS PROBLEMS GIVE ME YOUR E-MAILS AND I WILL SEND YOU THE WORKING FILE

That should do it...


None

Rystic

Reply To Post Reply & Quote

Posted at: 7/24/04 02:18 PM

Rystic LIGHT LEVEL 50

Sign-Up: 03/09/02

Posts: 956

I'm trying to dig up errors in this engine so I can fix them, too. If you encounter any errors, e-mail me the FLA (if you want to) or, if your an actionscripter, try modifying the code then mailing it to me. Thanks!


None

Rystic

Reply To Post Reply & Quote

Posted at: 7/24/04 02:49 PM

Rystic LIGHT LEVEL 50

Sign-Up: 03/09/02

Posts: 956

At 7/24/04 02:27 PM, TheAlmightyChet wrote: This doesn't seem to work for me...
Posted a link to download the fla HERE.

Your problem is that you moved the insides of the MC around. For some reason that messes it up. Go inside the clip and move it down a bit (until it works). Also, you can't have diagonal blocks; only horizontal and vertical.


None

Rystic

Reply To Post Reply & Quote

Posted at: 7/24/04 03:01 PM

Rystic LIGHT LEVEL 50

Sign-Up: 03/09/02

Posts: 956

At 7/24/04 02:54 PM, TheAlmightyChet wrote: Right then, I remade the character MC, but it still doesn't seem to work :\

Now you've moved it down too far. Try centering the body on the + sign thingie (this thing is wokring for me). It works when it is centered.


None

Rystic

Reply To Post Reply & Quote

Posted at: 7/24/04 03:06 PM

Rystic LIGHT LEVEL 50

Sign-Up: 03/09/02

Posts: 956

At 7/24/04 03:03 PM, TheAlmightyChet wrote: Oh yeah, it works. Thankee!

No problem, dude. And thank you for addressing this issue, which I believe others are struggling with. When you first make a MC, it is automatically centered. If you move it, however, this engine won't work. Moral: finalize your pictures before making them clips!


None

schorhr

Reply To Post Reply & Quote

Posted at: 7/24/04 03:32 PM

schorhr NEUTRAL LEVEL 11

Sign-Up: 05/28/02

Posts: 9,029

I have switched the settings so the default is not centered, due to my RPG /so the center is at the bottom / the feet ).


None

liquid-fyre

Reply To Post Reply & Quote

Posted at: 7/24/04 04:02 PM

liquid-fyre NEUTRAL LEVEL 01

Sign-Up: 06/28/04

Posts: 89

Could you guys plz tell me how to work this. i m a huge n00b


None

schorhr

Reply To Post Reply & Quote

Posted at: 7/24/04 04:08 PM

schorhr NEUTRAL LEVEL 11

Sign-Up: 05/28/02

Posts: 9,029

Draw a guy. Select it all, rightclick-> convert to symbol-> movieclip, name doesnt matter.

Now click the guy once, go to actions (F8 key) and paste the stuff inside.
Same with the wall code.


All times are Eastern Standard Time (GMT -5) | Current Time: 04:36 PM

<< Back

This topic is 13 pages long. [ 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 91113 ]

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!