Forum Topic: Problems with jumping engine.

(328 views • 18 replies)

This topic is 1 page long.

<< < > >>
None

Toast

Reply To Post Reply & Quote

Posted at: 10/25/05 05:01 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,414

It's not really broken, but it looks really weird.
Here's an example of my engine: http://img496.images..age=untitled14rx.swf

The good thing is that the ball doesn't fall through the ground AND that the ground is with slopes. But the jumping looks extremely un-reallistic.

Here's my code:


onClipEvent(enterFrame){

while(_root.ground.hitTest(this._x,this._y
,true)){
this._y --;
jump = false;
}
if(!_root.ground.hitTest(this._x,this._y,t
rue) && !jump){
fall = true;
}
if(fall == true){
_y += 5;
}
if(Key.isDown(Key.SPACE)){
jumping = true;
}else{
jumping = false;
}
if(!jump && jumping){
this._y -= vel;
vel = vel + gra / 2;
gra --;
}
if(gra < 1){
gra = 8;
jumping = false;
jump = true;
vel = 0;
fall = true;
}
trace("Velocity: " + vel + " Gravity: " + gra);
}

And here are the traced variables in the output window, I took them when the player was jumping. The problem is probably that one frame after the velocity is 17.5, it goes to 0 which makes it look like it hit teh roof. It should go like 0,2,5,10,15,13,9,5,2 or something like that...
Velocity: 0 Gravity: 8
Velocity: 4 Gravity: 7
Velocity: 7.5 Gravity: 6
Velocity: 10.5 Gravity: 5
Velocity: 13 Gravity: 4
Velocity: 15 Gravity: 3
Velocity: 16.5 Gravity: 2
Velocity: 17.5 Gravity: 1
Velocity: 0 Gravity: 8
Velocity: 0 Gravity: 8
Velocity: 0 Gravity: 8

I put on my robe and wizard hat

Why don't you check out my check out my userpage?

BBS Signature

None

Toast

Reply To Post Reply & Quote

Posted at: 10/25/05 05:16 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,414

BTW, here are my variables:

onClipEvent (load)
{
var jumping:Boolean = false;
var vel:Number = 0;
var gra:Number = 6;
var jump:Boolean = false;
var fall:Boolean = true;
}

I put on my robe and wizard hat

Why don't you check out my check out my userpage?

BBS Signature

None

Go0gley

Reply To Post Reply & Quote

Posted at: 10/25/05 05:33 AM

Go0gley LIGHT LEVEL 19

Sign-Up: 07/08/04

Posts: 218

if(!jump && jumping){
this._y -= vel;
vel = vel + gra / 2;
gra --;
}

What this does is that the ball rises only when it's hitTesting the ground. If it's not, it'll stop straight away. IM me for the fixed code (if I still have it lol).


None

Toast

Reply To Post Reply & Quote

Posted at: 10/25/05 06:43 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,414

No offence, googley, but your "fixed code" sucks ass :D

I have improved it a bit, now it looks a bit better although it is still un-reallistic.


onClipEvent (load)
{
jumping = false;
var topSpeed = 8;
var minSpeed = -8;
var xv = 0;
var xa = 2;
var vel:Number = 0;
var gra:Number = 6;
var jump:Boolean = false;
var fall:Boolean = true;
}
onClipEvent (enterFrame)
{
if(xv != 0){
play();
}
if (Key.isDown(65) && minSpeed < xv)
{
play();
xv = xv - xa;
this._xscale = -100;
}
if (Key.isDown(68) && xv < topSpeed)
{
play();
xv = xv + xa;
this._xscale = 100;
}
if (!Key.isDown(65) && !Key.isDown(68) && xv != 0)
{
xv = xv / 1.15;
}
if (xv >= -1 && xv <= 1)
{
xv = 0;
}
if (Key.isDown(87) && _root.floor >= this._y && yv == 0)
{
yv = 25;
}
if (this._y != _root.floor && this.platform == false)
{
yv = yv - xa;
}
if (yv < 2 && this._y >= _root.floor)
{
yv = 0;
}
if (_root.floor < this._y)
{
this._y = _root.floor;
}
this._x = this._x + xv;
this._y = this._y - yv;
while(_root.ground.hitTest(this._x,this._y
,true)){
this._y --;
jump = false;
}
if(!_root.ground.hitTest(this._x,this._y,t
rue) && !jump){
fall = true;
}
if(fall == true && !_root.ground.hitTest(this._x,this._y,true
)){
_y += 7;
}
if(Key.isDown(87)){
jumping = true;
}
if(!jump && jumping){
this._y -= vel;
vel = vel + gra / 2;
gra --;
}
if(gra < 1){
vel += 1;
}
if(gra < -8){
gra = 8;
jumping = false;
jump = true;
vel = 0;
fall = true;
}
trace("Velocity: " + vel + " Gravity: " + gra);
}

The output window says:

Velocity: 0 Gravity: 8
Velocity: 4 Gravity: 7
Velocity: 7.5 Gravity: 6
Velocity: 10.5 Gravity: 5
Velocity: 13 Gravity: 4
Velocity: 15 Gravity: 3
Velocity: 16.5 Gravity: 2
Velocity: 17.5 Gravity: 1
Velocity: 19 Gravity: 0
Velocity: 20 Gravity: -1
Velocity: 20.5 Gravity: -2
Velocity: 20.5 Gravity: -3
Velocity: 20 Gravity: -4
Velocity: 19 Gravity: -5
Velocity: 17.5 Gravity: -6
Velocity: 15.5 Gravity: -7
Velocity: 13 Gravity: -8
Velocity: 0 Gravity: 8

I put on my robe and wizard hat

Why don't you check out my check out my userpage?

BBS Signature

None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/25/05 06:49 AM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,429

The whole engine sucks ass
For a decent one talk to me and we'll go through it

- Matt, Rustyarcade.com


None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/25/05 07:04 AM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,429

It still sucks because if you ask me the whole thing needs redoing (with for loops for slopes to detect walls etc..)

Here is your crappy code re-mastered

//

onClipEvent (load) {
var jumping:Boolean;
var grav:Number;
var fall:Boolean;
}
onClipEvent (enterFrame) {
while (_root.ground.hitTest(this._x, this._y, true)) {
this._y--;
jumping = false;
}
if (!_root.ground.hitTest(this._x, this._y+10, true) && (!jumping)) {
fall = true;
this.grav = 0;
}
if (fall) {
_y += this.grav;
this.grav--;
}
if (Key.isDown(Key.SPACE)) {
if (!jumping) {
this.grav = -10;
jumping = true;
}
}
if (jumping) {
this._y += grav;
grav++;
}
}

//

Add in your own movement (space = jump)

- Matt, Rustyarcade.com


None

Toast

Reply To Post Reply & Quote

Posted at: 10/25/05 07:07 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,414

You can't just delete my movement code! >:(
Thanks for the code, but there are two bugs:
- it can just fly, instead of jumping(if you press space it just flies off screen)
- it doesn't work with slopes....

I think I will just keep my code..

I put on my robe and wizard hat

Why don't you check out my check out my userpage?

BBS Signature

None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/25/05 07:10 AM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,429

my bad I accidentally made grav -- instead of ++

Here is the correct code (though you should have figured that school-boy error on your own

onClipEvent (load) {
var jumping:Boolean;
var grav:Number;
var fall:Boolean;
}
onClipEvent (enterFrame) {
if(Key.isDown (Key.RIGHT)) {
this._x += 3
}
if (Key.isDown (Key.LEFT)) {
this._x -= 3
}
while (_root.ground.hitTest(this._x, this._y, true)) {
this._y--;
jumping = false;
}
if (!_root.ground.hitTest(this._x, this._y+10, true) && (!jumping)) {
fall = true;
this.grav = 0;
}
if (fall) {
_y += this.grav;
this.grav++
}
if (Key.isDown(Key.SPACE)) {
if (!jumping) {
this.grav = -10;
jumping = true;
}
}
if (jumping) {
this._y += grav;
grav++;
}
}

(I added a shitty movement in there for you to test it with)

http://img496.images..p?image=toast3vt.swf

Arrows and space

- Matt, Rustyarcade.com


None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/25/05 07:16 AM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,429

Oh for fuck sake I did it again!!!

onClipEvent (load) {
var jumping:Boolean;
var grav:Number;
var fall:Boolean;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x += 3;
}
if (Key.isDown(Key.LEFT)) {
this._x -= 3;
}
while (_root.ground.hitTest(this._x, this._y, true)) {
this._y--;
jumping = false;
fall = false
}

while(!_root.ground.hitTest(this._x, this._y+1, true) && (!jumping)) {
this._y ++
}

if (Key.isDown(Key.SPACE)) {
if (!jumping) {
this.grav = -10;
jumping = true;
}
}
if (jumping) {
this._y += grav;
grav++;
}
}

Okay the main problems with this engine is that you're using while loops. It means he magically teleports up and down stuff
Im tired of spoonfeeding you code so you'll have to figure it out on your own but here is the .swf

(mess around with the squares and you'll see what I mean - try walking off of one)

http://img463.images..p?image=toast0nd.swf

- Matt, Rustyarcade.com


None

dELtaluca

Reply To Post Reply & Quote

Posted at: 10/25/05 07:17 AM

dELtaluca LIGHT LEVEL 20

Sign-Up: 04/16/04

Posts: 5,117

you should make it more realistic and have the ball roll down the slopes ^^

My social worker says im special!

BBS Signature

None

Toast

Reply To Post Reply & Quote

Posted at: 10/25/05 07:23 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,414

At 10/25/05 07:17 AM, dELta_Luca wrote: you should make it more realistic and have the ball roll down the slopes ^^

Lol, I have another code for rolling down the slopes, but later in the game I will change the ball graphics, when the artist gives me the animations.
I just drew a ball because I can't draw :P

At 10/25/05 07:16 AM, Ninja-Chicken wrote: safdgfgjfkjghbgifkmngbhg

Nah, he doesn't "teleport" to the ground, he just doesn't fall through it!

Thanks anyway, I think I will use this one.

I put on my robe and wizard hat

Why don't you check out my check out my userpage?

BBS Signature

None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/25/05 07:25 AM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,429

At 10/25/05 07:16 AM, Ninja-Chicken wrote: safdgfgjfkjghbgifkmngbhg
Nah, he doesn't "teleport" to the ground, he just doesn't fall through it!

Thanks anyway, I think I will use this one.

No silly check my example you'll see what I mean - you will need to redo some unless you want all your ground to be connected

- Matt, Rustyarcade.com


Angry

unownedJR

Reply To Post Reply & Quote

Posted at: 10/25/05 07:28 AM

unownedJR NEUTRAL LEVEL 16

Sign-Up: 06/10/03

Posts: 2,335

Ah, another thread with so much AS code my head leaks juice.


None

Toast

Reply To Post Reply & Quote

Posted at: 10/25/05 07:35 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,414

At 10/25/05 07:28 AM, Rolli wrote: Ah, another thread with so much AS code my head leaks juice.

Yey, can I drink the tastey juice? :D

I put on my robe and wizard hat

Why don't you check out my check out my userpage?

BBS Signature

None

IWantSomeCookies

Reply To Post Reply & Quote

Posted at: 10/25/05 07:36 AM

IWantSomeCookies LIGHT LEVEL 13

Sign-Up: 08/20/04

Posts: 3,291

At 10/25/05 07:35 AM, -Toast- wrote:
At 10/25/05 07:28 AM, Rolli wrote: Ah, another thread with so much AS code my head leaks juice.
Yey, can I drink the tastey juice? :D

Its brain juice; will make you smarter. Lol.

"Actually, the server timed out trying to remove all your posts..."
-TomFulp


None

Toast

Reply To Post Reply & Quote

Posted at: 10/25/05 08:33 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,414

No. actually, I won't use your code, NC :P
Perhaps I should just copy the one from "I made a jumping engine for all"...

I put on my robe and wizard hat

Why don't you check out my check out my userpage?

BBS Signature

None

3ruce

Reply To Post Reply & Quote

Posted at: 10/25/05 08:45 AM

3ruce LIGHT LEVEL 09

Sign-Up: 07/23/05

Posts: 1,007

Toast shut the hell up and make one worthy with me mwa ha ha ha!!!
I'm joking.

Murad136, heres your fucking credit ;3

BBS Signature

None

Toast

Reply To Post Reply & Quote

Posted at: 10/25/05 08:47 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,414

At 10/25/05 08:45 AM, staircase wrote: Toast shut the hell up and make one worthy with me mwa ha ha ha!!!

...

I'm joking.

So shut up yourself :P

I put on my robe and wizard hat

Why don't you check out my check out my userpage?

BBS Signature

None

liaaaam

Reply To Post Reply & Quote

Posted at: 10/25/05 08:51 AM

liaaaam NEUTRAL LEVEL 21

Sign-Up: 12/11/04

Posts: 12,766

At 10/25/05 07:16 AM, Ninja-Chicken wrote: http://img463.images..p?image=toast0nd.swf

Aha, your hitTesting sucks balls..

Toast, redo the whole code.. but don't just copy and paste because something like this needs a heavy personalised code to suit the game exactly.


All times are Eastern Standard Time (GMT -5) | Current Time: 11:42 AM

<< Back

This topic is 1 page long.

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