Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Jumping, i've already looked elsewhere =(

Author
Message
kkun
17
Years of Service
User Offline
Joined: 10th Jun 2009
Location:
Posted: 9th Apr 2010 03:28


That code there i have is certainly for jump, but when i hold down the spacekey it keeps rising, how do i change that so i cant hold down the key?
Silvester
20
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 9th Apr 2010 09:44 Edited at: 9th Apr 2010 09:45
Add a trigger to the spacekey, e.g. SpaceKeyPressed.

Add this to the top of your code..


And then do something like this.



Note that this method will only let the character jump up ONE coordinate! To let it do more you'll have to change some values and add to the SpaceKeyPressed variable.


EDP Map Editor[2D]
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 9th Apr 2010 10:32
Most people use a Y speed for jumping, so if you imagine the vertical speed as a variable, if it's below 0 then the player is dropping, but with collision you end up with gravity basically.

The main thing is, you have a Y speed, decrease it every loop and add it to the player Y position. If the player collides with the floor, then set their Y speed to -0.1 or something slightly below zero and set their Y position to match the ground height. This is a basic player gravity system, and once it's in place it's very easy to add nice arched jumps - you only need to set the Y speed when the spacekey is pressed, and it sends the player into a jump.


Health, Ammo, and bacon and eggs!
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 9th Apr 2010 19:02
I've had trouble using a Y speed variable in games before unless you have a constant down-speed. Time-based gravity has a problem when you have different computers having different frame rates and not all frames have the same "time between frames" even on the same computer with a static scene..... Kinda wierd.... I've found that using a parabolic formula or using a sin wave to do the "up" portion works the best.

As far as keeping your character from jumping while still in the air, use Silvester's method..... That's the same type of method I use.

The fastest code is the code never written.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 9th Apr 2010 19:27 Edited at: 9th Apr 2010 19:28
Please... Don't use that method for jumping... It makes the player go up in a linear path and then down in a linear path, and that looks horrible.

What you need is gravity based jumping. Here's an example (I haven't compiled it, so I don't know if it runs or not):



TheComet

Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 9th Apr 2010 19:44
Quote: "It makes the player go up in a linear path and then down in a linear path, and that looks horrible."

It's only linear if you aren't moving....

The fastest code is the code never written.
Sepnon
16
Years of Service
User Offline
Joined: 7th Feb 2010
Location: Brazil
Posted: 9th Apr 2010 19:55
check if the player is on ground, if it is then jump

Login to post a reply

Server time is: 2026-07-26 17:36:56
Your offset time is: 2026-07-26 17:36:56