Newgrounds.com — Everything, By Everyone.

Checking login status…

USERNAME:

PASSWORD:

Logging in…

Logged in as:
.
Logging out…
Inbox My Account Log Out


Forum Topic: Platformer Glitch...

(214 views • 19 replies)

This topic is 1 page long.

<< < > >>
None

TomsPulp

Reply To Post Reply & Quote

Posted at: 5/10/08 12:58 AM

TomsPulp EVIL LEVEL 19

Sign-Up: 01/17/04

Posts: 1,365

http://spamtheweb.com/ul/upload/080508/8 6325_platformer2.php

WASD...

ok, see how somtimes your charecter ounces up and down a tiny tiny bit. Whats up with that?

Heres my code, I got it from a tutorial here on NG.

onClipEvent (load) {
var grav:Number = 0;
// gravity
var speed:Number = 9;
// how fast you walk
var jumpHeight:Number = 13;
// how high you jump
var slow:Number = .7;
// sets water falling speed
var slowspd:Number = speed/1.5;
// sets water walking speed
var setspeed:Number = speed;
var scale:Number = _xscale;
var ex:Number = 5;
// makes hitTests better, change for a closer hitTest (warning, more buggy if smalle, less real if further)
this.gotoAndStop(2);
}
onClipEvent (enterFrame) {
grav++;
_y += grav;
while (_root.ground.hitTest(_x, _y, true)) {
_y--;
grav = 0;
}
if (_root.water.hitTest(_x, _y, true)) {
if (grav>0) {
grav *= slow;
}
speed = slowspd;
} else {
speed = setspeed;
}
if (Key.isDown(68)) {
_x += speed;
_xscale = scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
} else if (Key.isDown(65)) {
_x -= speed;
_xscale = -scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
} else {
if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(79) && !Key.isDown(73)) {
this.gotoAndStop(3);
}
}
if (Key.isDown(79) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(73)) {
this.gotoAndStop(5);
}
if (Key.isDown(73) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(79)) {
this.gotoAndStop(4);
}
if (Key.isDown(87) && _root.ground.hitTest(_x, _y+3, true)) {
grav = -jumpHeight;
_y -= 4;
this.gotoAndStop(2);
}
if (_root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/2), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/6), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-_height, true)) {
_x -= speed;
}
if (_root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/2), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/6), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-_height, true)) {
_x += speed;
}
if (_root.ground.hitTest(_x, _y-_height-15, true)) {
grav = 1;
}
}

Oh no!!! what happen to all 5 thousand of my posts????? hehe

BBS Signature

Elated

arcansi

Reply To Post Reply & Quote

Posted at: 5/10/08 01:02 AM

arcansi LIGHT LEVEL 08

Sign-Up: 11/18/07

Posts: 934

while (_root.ground.hitTest(_x, _y, true)) {
_y--;
grav = 0;
}

That line of code, continuously pushes the character up one coordinate. So he keeps going up, then because of the variable gravity pulls him down 1. So he's constantly going up,down,up,down... Hope that helps. :)

True story...

BBS Signature

None

TomsPulp

Reply To Post Reply & Quote

Posted at: 5/10/08 01:10 AM

TomsPulp EVIL LEVEL 19

Sign-Up: 01/17/04

Posts: 1,365

At 5/10/08 01:02 AM, arcansi wrote: while (_root.ground.hitTest(_x, _y, true)) {
_y--;
grav = 0;
}

That line of code, continuously pushes the character up one coordinate. So he keeps going up, then because of the variable gravity pulls him down 1. So he's constantly going up,down,up,down... Hope that helps. :)

I see....so no way to get rid of it.....And the weird thing is, Sometimes you can see it, and sometimes yu cant.

Oh no!!! what happen to all 5 thousand of my posts????? hehe

BBS Signature

Elated

arcansi

Reply To Post Reply & Quote

Posted at: 5/10/08 01:18 AM

arcansi LIGHT LEVEL 08

Sign-Up: 11/18/07

Posts: 934

At 5/10/08 01:10 AM, TomsPulp wrote:
At 5/10/08 01:02 AM, arcansi wrote: while (_root.ground.hitTest(_x, _y, true)) {
_y--;
grav = 0;
}

That line of code, continuously pushes the character up one coordinate. So he keeps going up, then because of the variable gravity pulls him down 1. So he's constantly going up,down,up,down... Hope that helps. :)
I see....so no way to get rid of it.....And the weird thing is, Sometimes you can see it, and sometimes yu cant.

Well, if you make everything REALLY big, like stretch the vcam out and make everything like 10 times its size. You'll get a lot of lag but that problem will be gone. :)

Or, you can make it just a little bit bigger, and it may become unnoticable.

True story...

BBS Signature

None

ElDebugger

Reply To Post Reply & Quote

Posted at: 5/10/08 02:21 AM

ElDebugger NEUTRAL LEVEL 01

Sign-Up: 04/11/08

Posts: 162

while (_root.ground.hitTest(_x, _y, true)) {
_y--;
grav = 0;
}

Yeah, that's what it is. Just get rid of it. I don't see why you would code the character to shift up by one pixel everytime when he hits the ground. You literally coded it to vibrate when he is on the ground.

I think that the guy who gave you this code did it to compensate for something in his character movieclip, but it's not necessary. Get rid of that section of code, the "_y --;" part. Change the code so that when your character touches the ground, his "y" equals the ground level.
http://spamtheweb.com/ul/upload/090508/8 3252_TomsPulp2.fla

Got a broken PSP? Click here and have it fixed for cheap!

BBS Signature

None

Coaly

Reply To Post Reply & Quote

Posted at: 5/10/08 02:33 AM

Coaly DARK LEVEL 20

Sign-Up: 08/11/04

Posts: 2,473

Actually, all of you are wrong.

The problem is at the beginning of the enterframe you add one to grav and then move the character's _y position. You need to write it to only add to the gravity if he is not on the ground.

I think you could squeeze this in here, because this is testing if just below the character is on the ground. Also, put the grav++; after the _y += grav;

if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
grav = 0;
} else {
this.gotoAndStop(2);
}

I think that will work, definitely don't remove that while loop, what that does is if the character is moving 20px a frame, and goes 10px underground, it moves the character up to be on the ground.

profile | pm me | sig by bomtumes

BBS Signature

Mad as Hell

BloodSucker150

Reply To Post Reply & Quote

Posted at: 5/10/08 03:10 AM

BloodSucker150 LIGHT LEVEL 09

Sign-Up: 03/20/08

Posts: 406

you didn't make this code!
you just copy all from here:
http://www.newgrounds.com/portal/view/42 6598
!@!!!!!!!


None

Coaly

Reply To Post Reply & Quote

Posted at: 5/10/08 03:20 AM

Coaly DARK LEVEL 20

Sign-Up: 08/11/04

Posts: 2,473

At 5/10/08 03:10 AM, BloodSucker150 wrote: you didn't make this code!
you just copy all from here:
http://www.newgrounds.com/portal/view/42 6598
!@!!!!!!!
At 5/10/08 12:58 AM, TomsPulp wrote: Heres my code, I got it from a tutorial here on NG.

No shit Sherlock, you have enough time to read the code and figure out where it's from but not enough time to read the first paragraph of the first post?

profile | pm me | sig by bomtumes

BBS Signature

Shouting

BloodSucker150

Reply To Post Reply & Quote

Posted at: 5/10/08 05:16 AM

BloodSucker150 LIGHT LEVEL 09

Sign-Up: 03/20/08

Posts: 406

hahaha ok
but why you need help to copy pase those codes???


None

Hoeloe

Reply To Post Reply & Quote

Posted at: 5/10/08 06:13 AM

Hoeloe LIGHT LEVEL 20

Sign-Up: 04/29/04

Posts: 3,391

At 5/10/08 05:16 AM, BloodSucker150 wrote: hahaha ok
but why you need help to copy pase those codes???

He doesn't. You didn't read it.

The problem is a weird glitch in flash, put the camera on the lowest layer, since I assume you are using a v-cam. Sometimes that glitch happens if the cam is above the player, so put the cam on the lowest layer to fix it.

Theory is wrong.
------------------------------
THE LAST WIZARD AND THE DOOMSDAY RINGS NOW IN PRODUCTION!

BBS Signature

None

Coaly

Reply To Post Reply & Quote

Posted at: 5/10/08 01:07 PM

Coaly DARK LEVEL 20

Sign-Up: 08/11/04

Posts: 2,473

At 5/10/08 06:13 AM, Hoeloe wrote: The problem is a weird glitch in flash, put the camera on the lowest layer, since I assume you are using a v-cam. Sometimes that glitch happens if the cam is above the player, so put the cam on the lowest layer to fix it.

False. How would the vcam affect one movieclip to move up and down and not affect anything else on the screen, that's sillier than removing the while loop.

profile | pm me | sig by bomtumes

BBS Signature

None

Wolfears2

Reply To Post Reply & Quote

Posted at: 5/10/08 01:35 PM

Wolfears2 EVIL LEVEL 08

Sign-Up: 10/20/07

Posts: 672

It's AS3, so my opinion is totally worthless, but I would so it so that it changes the _y by 0 while it is touching the ground. Works like that for me.

Tomspulp? Not seen you in ages.

Yay, I have a sig again. Go join teh falling egg collab NAOW! www.freewebs.com/wolfears2 is up with some basic stuff on. More coming soon.

BBS Signature

None

LCurtis

Reply To Post Reply & Quote

Posted at: 5/10/08 03:00 PM

LCurtis NEUTRAL LEVEL 17

Sign-Up: 05/23/07

Posts: 1,077

At 5/10/08 01:35 PM, Wolfears2 wrote: It's AS3, so my opinion is totally worthless, but I would so it so that it changes the _y by 0 while it is touching the ground. Works like that for me.

It's AS2.

support the dream ...

BBS Signature

None

Hoeloe

Reply To Post Reply & Quote

Posted at: 5/10/08 03:06 PM

Hoeloe LIGHT LEVEL 20

Sign-Up: 04/29/04

Posts: 3,391

At 5/10/08 01:07 PM, Coaly wrote: False. How would the vcam affect one movieclip to move up and down and not affect anything else on the screen, that's sillier than removing the while loop.

It is true. I have no idea why it does it, but it does. It also messes up some types of platformer AI. When you try it, then tell me it is false.

Theory is wrong.
------------------------------
THE LAST WIZARD AND THE DOOMSDAY RINGS NOW IN PRODUCTION!

BBS Signature

None

Wolfears2

Reply To Post Reply & Quote

Posted at: 5/10/08 03:09 PM

Wolfears2 EVIL LEVEL 08

Sign-Up: 10/20/07

Posts: 672

At 5/10/08 03:00 PM, LCurtis wrote:
At 5/10/08 01:35 PM, Wolfears2 wrote: It's AS3, so my opinion is totally worthless, but I would so it so that it changes the _y by 0 while it is touching the ground. Works like that for me.
It's AS2.

Oh. Looked too confusing for that >.<

Yay, I have a sig again. Go join teh falling egg collab NAOW! www.freewebs.com/wolfears2 is up with some basic stuff on. More coming soon.

BBS Signature

None

Hoeloe

Reply To Post Reply & Quote

Posted at: 5/10/08 03:11 PM

Hoeloe LIGHT LEVEL 20

Sign-Up: 04/29/04

Posts: 3,391

Anyway, my fix will work, this happens to me all the time and I fix it like that. The glitch only occurs if you have a cam above the player. Take the cam off, no glitch, put the can below the player, no glitch. And I think the reason it only affects the player movieclip is because the cam is following the player movieclip.

Theory is wrong.
------------------------------
THE LAST WIZARD AND THE DOOMSDAY RINGS NOW IN PRODUCTION!

BBS Signature

None

KyleDaFox

Reply To Post Reply & Quote

Posted at: 5/10/08 03:19 PM

KyleDaFox EVIL LEVEL 23

Sign-Up: 04/23/05

Posts: 1,954

Hoeloe's suggestion works, I tried it and it works like a charm.


None

TomsPulp

Reply To Post Reply & Quote

Posted at: 5/10/08 03:37 PM

TomsPulp EVIL LEVEL 19

Sign-Up: 01/17/04

Posts: 1,365

At 5/10/08 03:19 PM, KyleDaFox wrote: Hoeloe's suggestion works, I tried it and it works like a charm.

I moved the v-cams layer to the lowest one, it still bounces......and those other things dont work.

Oh no!!! what happen to all 5 thousand of my posts????? hehe

BBS Signature

None

TomsPulp

Reply To Post Reply & Quote

Posted at: 5/10/08 03:46 PM

TomsPulp EVIL LEVEL 19

Sign-Up: 01/17/04

Posts: 1,365

I fixed it!
(code on vcam)

onClipEvent (enterFrame) {
_y += (_root.player._y-_y)/1;
_x += (_root.player._x-_x)/1;
}

^^^^ the 1 used to be a 4.

Now it dosent ounce or anything.

Oh no!!! what happen to all 5 thousand of my posts????? hehe

BBS Signature

None

Coolio-Niato

Reply To Post Reply & Quote

Posted at: 5/10/08 05:11 PM

Coolio-Niato LIGHT LEVEL 22

Sign-Up: 06/30/05

Posts: 1,591

At 5/10/08 03:46 PM, TomsPulp wrote:
_x += (_root.player._x-_x)/1;

Dammit! I was just about to say that the reason behind it is that the _root. moved FRACTIONS of a pixel. By doing /1 you could fix it, but you could also do

: _x += Math.round((_root.player._x-_x)/4);

=)

BBS Signature

All times are Eastern Daylight Time (GMT -4) | Current Time: 10:09 PM

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