Forum Topic: AS2 problem

(99 views • 11 replies)

This topic is 1 page long.

<< < > >>
None

7IsUnlucky

Reply To Post Reply & Quote

Posted at: 11/3/09 07:03 PM

7IsUnlucky FAB LEVEL 25

Sign-Up: 06/12/07

Posts: 1,953

I'm making a physics engine, but one of the biggest problems I've run into is having the character stop right when he hits the platform: he usually stops 10 or so pixels in. Am I right in thinking this is because it's 30 fps and the enterFrame doesn't work fast enough for it? Is there a way to fix it?

Programming languages I know: AS2 and TRS-80 BASIC

BBS Signature

None

zrb

Reply To Post Reply & Quote

Posted at: 11/3/09 07:07 PM

zrb LIGHT LEVEL 11

Sign-Up: 08/08/06

Posts: 4,539

Use a while loop to push him out of it.

School Sux ! || As :Main || As3: Main || Animation: Main || Flash Tutorials ||

BBS Signature

None

TheBoob

Reply To Post Reply & Quote

Posted at: 11/3/09 07:10 PM

TheBoob NEUTRAL LEVEL 12

Sign-Up: 04/12/02

Posts: 386

Its hard to tell for sure what problems your running into, but normaly the problem is something like this:

_ySpeed is like 20, and the character is 10 px above the ground.

he moves down 20 px, so now he is hitting the ground (which im guessing tirggers an event, to stop gravity from working and set his _ySpeed to 0.

The problem though, is this stops the character from falling, but the character is 10 px into the ground already. so what youw ant to do is something like.

if(hitTest){
_ySpeed = 0.
//stop gravity
char.y = top of the ground.y
}

obviously not real code, but should give you the idea

Hope this helps


None

7IsUnlucky

Reply To Post Reply & Quote

Posted at: 11/3/09 07:11 PM

7IsUnlucky FAB LEVEL 25

Sign-Up: 06/12/07

Posts: 1,953

At 11/3/09 07:07 PM, zrb wrote: Use a while loop to push him out of it.

It worked...

but it made flash crash

god DAMNIT

Programming languages I know: AS2 and TRS-80 BASIC

BBS Signature

None

zrb

Reply To Post Reply & Quote

Posted at: 11/3/09 07:20 PM

zrb LIGHT LEVEL 11

Sign-Up: 08/08/06

Posts: 4,539

At 11/3/09 07:11 PM, 7IsUnlucky wrote: It worked...
but it made flash crash
god DAMNIT

Be sure to not have an if and while hitTest on the same position, like this:

if (blah.hitTest(_x,_y+1,true)) {
//blaah
}
while (blah.hitTest(_x,_y+1,true)) {
//blaah
}

That crashes flash all the time.

School Sux ! || As :Main || As3: Main || Animation: Main || Flash Tutorials ||

BBS Signature

None

7IsUnlucky

Reply To Post Reply & Quote

Posted at: 11/3/09 07:22 PM

7IsUnlucky FAB LEVEL 25

Sign-Up: 06/12/07

Posts: 1,953

I just have the while

Programming languages I know: AS2 and TRS-80 BASIC

BBS Signature

None

zrb

Reply To Post Reply & Quote

Posted at: 11/3/09 07:24 PM

zrb LIGHT LEVEL 11

Sign-Up: 08/08/06

Posts: 4,539

At 11/3/09 07:22 PM, 7IsUnlucky wrote: I just have the while

Then you should :
"Post some fucking code"
-- 7IsUnlucky

School Sux ! || As :Main || As3: Main || Animation: Main || Flash Tutorials ||

BBS Signature

None

7IsUnlucky

Reply To Post Reply & Quote

Posted at: 11/3/09 07:27 PM

7IsUnlucky FAB LEVEL 25

Sign-Up: 06/12/07

Posts: 1,953

onClipEvent(load){
	xspd = 0;
	yspd = 0;
}
onClipEvent(enterFrame){
	_x += xspd;
	_y += yspd;
	yspd += 1;
	while(this.hitTest(_root.p1) or this.hitTest(_root.p2)){
		yspd = 0;
	}
}

Programming languages I know: AS2 and TRS-80 BASIC

BBS Signature

None

zrb

Reply To Post Reply & Quote

Posted at: 11/3/09 07:29 PM

zrb LIGHT LEVEL 11

Sign-Up: 08/08/06

Posts: 4,539

At 11/3/09 07:27 PM, 7IsUnlucky wrote: onClipEvent(load){
xspd = 0;
yspd = 0;
}
onClipEvent(enterFrame){
_x += xspd;
_y += yspd;
yspd += 1;
while(this.hitTest(_root.p1) or this.hitTest(_root.p2)){
yspd = 0;
}
}

Weird, doesn't look wrong.
But you didn't get what I meant:

onClipEvent(load){
	xspd = 0;
	yspd = 0;
}
onClipEvent(enterFrame){
	_x += xspd;
	_y += yspd;
	yspd += 1;
	if(this.hitTest(_root.p1) or this.hitTest(_root.p2)){
		yspd = 0;
	}
while (_root.p1.hitTest(_x,_y-5,true)) {
_y--
}
}

Basically you should use a while loop to push him up when he's far in and us an if to detect ground collisions.
That code might not work but the concept works all the time.

School Sux ! || As :Main || As3: Main || Animation: Main || Flash Tutorials ||

BBS Signature

None

7IsUnlucky

Reply To Post Reply & Quote

Posted at: 11/3/09 07:33 PM

7IsUnlucky FAB LEVEL 25

Sign-Up: 06/12/07

Posts: 1,953

That doesn't work

Programming languages I know: AS2 and TRS-80 BASIC

BBS Signature

None

Fion

Reply To Post Reply & Quote

Posted at: 11/3/09 07:43 PM

Fion LIGHT LEVEL 34

Sign-Up: 08/21/05

Posts: 2,373

The problem when it crashed was that you werent actually getting him out of the ground you were just setting yspd to 0 and because the character was still touching the platform it continued to loop through the code and he never got moved out with the code inside, an infinite loop.

Essentially you should be able to do the following:

onClipEvent(load){
	xspd = 0;
	yspd = 0;
}
onClipEvent(enterFrame){
	_x += xspd;
	_y += yspd;
	yspd += 1;
	if (this.hitTest(_root.p1) || this.hitTest(_root.p2)){
		yspd = 0;
	}
	while (this.hitTest(_root.p1) || this.hitTest(_root.p2)) {
		_y--
	}
}

This is should work but is likely to make the character sort of bounce on the surface of the ground if you catch my meaning.

However if that doesn't work well maybe you can try figuring the y position required to be above the ground then not use the while statement but in the if statement and a line that sets the _y value to the location on the surface of the ground.


None

zrb

Reply To Post Reply & Quote

Posted at: 11/3/09 07:46 PM

zrb LIGHT LEVEL 11

Sign-Up: 08/08/06

Posts: 4,539

At 11/3/09 07:33 PM, 7IsUnlucky wrote: That doesn't work

Don't just copy paste, try to understand the concept I'm telling you >:|
I already mentionned it probably wouldn't work.

School Sux ! || As :Main || As3: Main || Animation: Main || Flash Tutorials ||

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 02:50 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!