Be a Supporter!

I've made a jumping engine for all.

  • 36,307 Views
  • 373 Replies
New Topic Respond to this Topic
Rystic
Rystic
  • Member since: Mar. 9, 2002
  • Offline.
Forum Stats
Member
Level 60
Blank Slate
I've made a jumping engine for all. Jul. 23rd, 2004 @ 10:31 PM Reply

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;
}
}

Rystic
Rystic
  • Member since: Mar. 9, 2002
  • Offline.
Forum Stats
Member
Level 60
Blank Slate
Response to I've made a jumping engine for all. Jul. 23rd, 2004 @ 10:33 PM Reply

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;
}
}

Deathcon7
Deathcon7
  • Member since: Oct. 1, 2003
  • Offline.
Forum Stats
Member
Level 21
Writer
Response to I've made a jumping engine for all. Jul. 23rd, 2004 @ 10:45 PM Reply

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

Rystic
Rystic
  • Member since: Mar. 9, 2002
  • Offline.
Forum Stats
Member
Level 60
Blank Slate
Response to I've made a jumping engine for all. Jul. 23rd, 2004 @ 10:47 PM Reply

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...

Taylor
Taylor
  • Member since: Aug. 19, 2003
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to I've made a jumping engine for all. Jul. 23rd, 2004 @ 11:57 PM Reply

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;
}
}

MidnyteRayne
MidnyteRayne
  • Member since: Jul. 15, 2004
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 12:23 AM Reply

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

Rystic
Rystic
  • Member since: Mar. 9, 2002
  • Offline.
Forum Stats
Member
Level 60
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 07:07 AM Reply

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.

Rystic
Rystic
  • Member since: Mar. 9, 2002
  • Offline.
Forum Stats
Member
Level 60
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 07:09 AM Reply

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.

cuber3
cuber3
  • Member since: Apr. 2, 2004
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 07:37 AM Reply

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 !!

Mazza
Mazza
  • Member since: Feb. 10, 2002
  • Offline.
Forum Stats
Member
Level 35
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 08:11 AM Reply

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


fucking magnets man how do they work

molkman
molkman
  • Member since: Mar. 12, 2004
  • Offline.
Forum Stats
Member
Level 08
Game Developer
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 08:32 AM Reply

ooooh guys... looks difficult^^


XO

Rystic
Rystic
  • Member since: Mar. 9, 2002
  • Offline.
Forum Stats
Member
Level 60
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 09:26 AM Reply

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.

Rystic
Rystic
  • Member since: Mar. 9, 2002
  • Offline.
Forum Stats
Member
Level 60
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 09:27 AM Reply

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?

adit-ya-sharma
adit-ya-sharma
  • Member since: Apr. 11, 2004
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 09:33 AM Reply

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

GeoffCLogan
GeoffCLogan
  • Member since: Apr. 25, 2004
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 10:15 AM Reply

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......

schorhr
schorhr
  • Member since: May. 28, 2002
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 10:52 AM Reply

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

Ercle
Ercle
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 10:52 AM Reply

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?

schorhr
schorhr
  • Member since: May. 28, 2002
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 10:53 AM Reply

Jumping works fine here?

schorhr
schorhr
  • Member since: May. 28, 2002
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 11:16 AM Reply

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.

Taylor
Taylor
  • Member since: Aug. 19, 2003
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 01:24 PM Reply

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

Rystic
Rystic
  • Member since: Mar. 9, 2002
  • Offline.
Forum Stats
Member
Level 60
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 02:13 PM Reply

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

Rystic
Rystic
  • Member since: Mar. 9, 2002
  • Offline.
Forum Stats
Member
Level 60
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 02:14 PM Reply

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?

Rystic
Rystic
  • Member since: Mar. 9, 2002
  • Offline.
Forum Stats
Member
Level 60
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 02:17 PM Reply

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

That should do it...

Rystic
Rystic
  • Member since: Mar. 9, 2002
  • Offline.
Forum Stats
Member
Level 60
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 02:18 PM Reply

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!

Rystic
Rystic
  • Member since: Mar. 9, 2002
  • Offline.
Forum Stats
Member
Level 60
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 02:49 PM Reply

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.

Rystic
Rystic
  • Member since: Mar. 9, 2002
  • Offline.
Forum Stats
Member
Level 60
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 03:01 PM Reply

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.

Rystic
Rystic
  • Member since: Mar. 9, 2002
  • Offline.
Forum Stats
Member
Level 60
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 03:06 PM Reply

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!

schorhr
schorhr
  • Member since: May. 28, 2002
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 03:32 PM Reply

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

liquid-fyre
liquid-fyre
  • Member since: Jun. 28, 2004
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 04:02 PM Reply

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

schorhr
schorhr
  • Member since: May. 28, 2002
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to I've made a jumping engine for all. Jul. 24th, 2004 @ 04:08 PM Reply

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.