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.

Code Snippets / Jumping Function (DBP)

Author
Message
RUCCUS
20
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 21st Jul 2005 03:58 Edited at: 21st Jul 2005 04:42
Jumping
By RUCCUS of RUCCUS.net

<EDIT> I've got an error to fix, the system works for one person fine</EDIT>

<EDIT 2> Ack, basically if you want the system to work for multiple objects take it out of the function and name each variable diferently, if that makes sense. I suck at using types so this might take a while to make it compatbile for more than one object.</EDIT 2>


When I was starting out I had troubles with creating some basic jumping code, so here it is. Gravity isn't supplied so you'll have to work that out for yourself, but this should be a good starter.

Just include this code before the main loop:



And then add this code after the main loop:



Finally, call the JUMP function every loop. To activate the JUMP function, simply set JUMP# to 1. The function will automatically jump once and then make JUMP# equal 0 again.

SYNTAX:
JUMP(Object Number, Jump Speed, Jump Height)

Im working on adding in some basic physics so the user slows as they reach the height extent and then speed up again as they fall down. I should have it done soon, but no guarantees. Until then if you need physics im sure you can come up with a formula of your own

An example of using the function in the loop:



Tips:

- Make sure you over ride the jump function when you land on something or the function will keep moving you down until you get to ground level.

How? Just make the program call the JUMP() function when the user isn't colliding with anything below them. And when the user does collide with something below them, reset the JUMP# variable to 0.

- The user only falls until they reach their ground level or original y height when they pressed the spacekey. So if the user is up high and jumps off of a ledge the user will fall only to their previous y, and will then float in the air.

How can I fix this? With the implementation of some basic gravity the system will keep moving the user down. I'd suggest moving the user down at all times as long as they are
1. Not standing on anything
2. Not jumping
But thats just a suggestion since gravity functions differ a lot from program to program.


Current Projects: SHADE - Game Maker | Mecho - TGC Puzzle Entry | Halo Physics Engine | COLD - Polygonal Collision Detection
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 29th Jul 2005 21:32
What I do is have a thrust variable which is taken off of the players Y position every loop, and decrement thrust by a gravity constant if the player is not touching the ground. Therefore to jump I just set thrust to a positive(or negative depending on how you set it up) value and it handles itself.


"Lets migrate like bricks" - Me
RUCCUS
20
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 30th Jul 2005 16:14
I made a much better source for jumping than this one in The Newcommer's Guide to Creating First Person Shooter's. Ill update this with that later, it's kind of like your system.


NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 31st Jul 2005 02:17 Edited at: 31st Jul 2005 02:19
RUCCUS,




+NanoBrain+
RUCCUS
20
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 31st Jul 2005 03:44 Edited at: 31st Jul 2005 03:49
That's almost exactly like the code featured in the FPS tut im making (click sig). Only real difference is the speed at which the user jumps.


Login to post a reply

Server time is: 2025-05-16 03:14:00
Your offset time is: 2025-05-16 03:14:00