Be a Supporter!

Moar gravity help

  • 272 Views
  • 5 Replies
New Topic Respond to this Topic
LeonCross
LeonCross
  • Member since: Sep. 22, 2007
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Moar gravity help 2010-08-03 08:52:09 Reply

Ok, I managed to beat my head against the wall enough to get it to semi work.

On character:

if (!touchingGround)
{
grav++;
this._y += grav;
}
else
{
grav = 0;
}

On objects:

onClipEvent (enterFrame) {
if ((_currentframe == 1) and (this.hitTest(_root.hero)))
{
_root.hero.touchingGround = (true);
}
}

The problem is, of course, that once a character touches one of these objects, gravity is switched off permanently.

I tried making a flat

touchingGround = (false);

on the character, but then the two just fight over who wins...and gravity eventually does.

I assume there is a simple way to make touchingGround = false if it's not getting constant feedback otherwise?

wagnerben
wagnerben
  • Member since: May. 27, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to Moar gravity help 2010-08-03 09:06:23 Reply

this is probably more than what you wanted, but this tut shows the full creating of a platformer game...so the jump & gravity code is in there

hope it helps


i like to have fun with the girls.

BBS Signature
Montycarlo
Montycarlo
  • Member since: Mar. 14, 2005
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Moar gravity help 2010-08-03 09:23:48 Reply

Your code's flaw is that you're not detecting when the character 'falls' off from the edge of a platform.

A better approach would be to detect if the character is on the ground (or will be on the ground after the velocity +gravity is applied) and if so, set the y-velocity to 0.


Although practicality beats purity.
Errors should never pass silently.
In the face of ambiguity, refuse the temptation to guess.

LeonCross
LeonCross
  • Member since: Sep. 22, 2007
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Moar gravity help 2010-08-03 10:36:51 Reply

touchingGround is a simple boolean variable that's either on or off.

Hm. I have no idea how I'd go about that. 0.o

Yambanshee
Yambanshee
  • Member since: Oct. 5, 2008
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to Moar gravity help 2010-08-03 13:01:53 Reply

you have to either loop through all your objects your hitting against on the character, or put all the objects into 1 movieclip and hittest against that.


AS2||AS3||Motox
Thanks to hdxmike for the sig :]

BBS Signature
LeonCross
LeonCross
  • Member since: Sep. 22, 2007
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Moar gravity help 2010-08-03 19:24:28 Reply

Design the level, then select them all and make them a movie? ^_^. That could work very well. Thanks for the advice!

I tried using a "while" command in place of for. Like "while blah blah code for hit test is true, touchingGround = true."

Unfortunately, flash didn't like that and crashed, so I'm guessing I don't understand the correct use of while. xD