Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Blastfrog

Question about coding

Recommended Posts

So, I'm trying to edit Hexen's jumping code to cut the player's jump off if they're not holding the button. Unfortunately, it seems to ignore that I tell it to reduce the z velocity to 2.83 if it's greater than that, when the player is in midair but is NOT holding the jump button. How would I go about fixing this?

if ((cmd->arti & AFLAG_JUMP) && onground)
{
	player->mo->momz = 6.33 * FRACUNIT;
	player->mo->flags2 &= ~MF2_ONMOBJ;
}
if (!(cmd->arti & AFLAG_JUMP) && !onground && player->mo->momz > 2.83)
{
	player->mo->momz = 2.83 * FRACUNIT;
}

Share this post


Link to post

I don't know anything about the Doom source, but don't you have to multiply by FRACUNIT in the if statement? I.e.

if (!(cmd->arti & AFLAG_JUMP) && !onground && player->mo->momz > 2.83 * FRACUNIT)

Share this post


Link to post
boris said:

I don't know anything about the Doom source, but don't you have to multiply by FRACUNIT in the if statement? I.e.

if (!(cmd->arti & AFLAG_JUMP) && !onground && player->mo->momz > 2.83 * FRACUNIT)

Oh, shit, you're right. Either way, in that case, it should still be cutting off the jump, assuming that fracunit is over, and not under 1.

Share this post


Link to post

You're gonna have to get a little more serious if you want this behavior. This is a 1-time check for the jump button, and it propels you 6.33 whatevers that 1 time.

My approach would be to figure how that works out over TICs. Say for example the top height (assuming normal gravity) is reached after 10 TICs. You can check every TIC to see if the jump button is held and add another 6.33/10 momz thrust. You would also have to see how many thrusts you'd already applied so you don't jump infinitely.

Share this post


Link to post

Fairly standard feature in video game jumps (though I find it interesting that Pitfall on the Atari 2600 deliberately avoided that); no matter how non-sensical it is in real-world terms it's basically standard.

Hell as far as real world terms go, jumping barely gets you any height and it certainly doesn't speed you up ;)

Share this post


Link to post

Well, I got this working as intended. Maes suggested to me that I use an "unjump" flag, so that it would be 1 if the jump button is NOT being pressed. After implementing this, the jumping feels very Mario-like now. If you're wondering about the rather low values of vertical momentum, note that the gravity is lower.

Ladna said:

You're gonna have to get a little more serious if you want this behavior. This is a 1-time check for the jump button, and it propels you 6.33 whatevers that 1 time.

My approach would be to figure how that works out over TICs. Say for example the top height (assuming normal gravity) is reached after 10 TICs. You can check every TIC to see if the jump button is held and add another 6.33/10 momz thrust. You would also have to see how many thrusts you'd already applied so you don't jump infinitely.

Surprisingly, many games from the era that did this with jumping didn't handle it the way you describe. It literally only did just one push that was your maximum jump height, and it would go uninterrupted only as long as you still held the jump button down, otherwise it would cap off your vertical momentum if it was already above the cap's value. Mario and Sonic did it this way, at least.

wesleyjohnson said:

Unless this player character has wings or a jet pack, Why are they able to modify their path after leaving the ground ??

because vidya gaim logic

Chungy pretty much explained it better than I could.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×