Be a Supporter!

Jump programming question.

  • 294 Views
  • 7 Replies
New Topic Respond to this Topic
2ndself
2ndself
  • Member since: Mar. 15, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Jump programming question. 2010-08-03 07:47:03 Reply

I'm no noob; I know how to program a normal 'sprite.dy = -7 and then affect sprite.dy++ every frame for gravity' jump, as seen in the majority of games, but I've hit a bit of a hurdle at the moment.

What I'm after is a retro - and quite rarely seen - fixed length and direction jump, like in the original Castlevania, or Faxanadu. And I'm in a world of hurt trying to figure out how to do it. I've tried searching google but I don't know any proper name for this sort of jump, so it's useless.

Any ideas? Links?
Thanks.

Actionscript 2 btw.

wagnerben
wagnerben
  • Member since: May. 27, 2007
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to Jump programming question. 2010-08-03 08:27:28 Reply

i don't....but jetpack paladin is awesome!
=]


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 Jump programming question. 2010-08-03 08:39:09 Reply

I think I know what you mean - There is no transition between the uppermost point in the jump and when the character leaves the ground?

If so, simply store a Number variable and decrement it each frame if it is above 0. It serves as a timer for how much time is left in the 'current' jump. You could therefore set an offset to the y-value when the jump finishes and when it begins.

var jumpTimer:Number = 0;
var jumpOffset:Number = 25
if(jumpTimer > 0){
    jumpTimer--;
    if(!jumpTimer)  y+= jumpOffset;
}else{
    if(Key.isDown(Key.UP)){
        jumpTimer = 10
        y -= jumpOffset;
    }
}

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

Montycarlo
Montycarlo
  • Member since: Mar. 14, 2005
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Jump programming question. 2010-08-03 08:40:14 Reply

Argh - in my last post there is one too many spaces after one of the conditionals. Here is the functional code:

var jumpTimer:Number = 0;
var jumpOffset:Number = 25
if(jumpTimer > 0){
    jumpTimer--;
    if(!jumpTimer) y+= jumpOffset;
}else{
    if(Key.isDown(Key.UP)){
        jumpTimer = 10
        y -= jumpOffset;
    }
}

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

2ndself
2ndself
  • Member since: Mar. 15, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Jump programming question. 2010-08-03 08:47:25 Reply

Yes that's sort of what I mean. But there IS some transition between the peak of the jump and the launch, it's just that at the peak the character seems to hover slightly before falling again.

It is the rate and timing of the climb, hover and drop I'm having dificulty with.
Thanks though.

Montycarlo
Montycarlo
  • Member since: Mar. 14, 2005
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to Jump programming question. 2010-08-03 09:11:10 Reply

Store a flag for jumping and detect when the y-velocity becomes positive. When so, set the y-velocity to 0 and don't apply gravity until a timer variable is 0 or less.


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

2ndself
2ndself
  • Member since: Mar. 15, 2006
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to Jump programming question. 2010-08-03 09:32:52 Reply

At 8/3/10 08:27 AM, wagnerben wrote: i don't....but jetpack paladin is awesome!
=]

Thanks btw XD

And thanks for your help Montycarlo. This mess is made worse by the precision I'm trying to get into it. I'm looking currently at using an array to store the y axis movement for each frame of the jump, like so:

sprite.jumpPattern = [-7, -7, -5, -5, -3, -3, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 3, 3, 5, 5, 7, 7];

Might seem overly complicated but it seems to be working quite nicely.

Yambanshee
Yambanshee
  • Member since: Oct. 5, 2008
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to Jump programming question. 2010-08-03 13:08:23 Reply

Montycarlo's method will work better, because your going to have troubles when your jumping off a slope or onto one.


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

BBS Signature