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.

Newcomers DBPro Corner / Jumping problems!

Author
Message
Jake025
16
Years of Service
User Offline
Joined: 28th Aug 2008
Location:
Posted: 11th Nov 2008 02:00
I have been creating a simple 3d platform game and I needed the character to be able to jump from platform to platform. I created a little program, which you can see here, to try and create a character that can jump.



There seems to be something wrong with the jumping part. If you hold the spacebar, you keep on going up. I know why this is, but I can't figure out a way to stop it. Is there something simple I am doing wrong? Or do I need to add more to my code?
Tom0001
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location:
Posted: 11th Nov 2008 13:31 Edited at: 11th Nov 2008 13:34
Yes. Find the object's y position when the jump begins and set it to a variable, then make a new variable = previousvariableofyposition = previousvariableofyposition + <however much y position the object will move up before gravity kicks in>. Then, have a line for when the object y position = <variable name> Then <blablabla, code to move the player back down/reduce the y position of the object until it equals the previous variable for where he was when he began the jump.

EDIT: So basically, the code would be something like this added to the main loop.

This line goes just before the jump code begins, after the spacebar is pressed:

objyposition# = object position y(<objnum>

Then, add this after that.

jumpfullheight# = objyposition# + <num, say 500>

Then, add somewhere in the middle area of the jump code:

If object position y(1) = jumpfullheight#
<code to finish jump and start plr moving down here>
EndIf

Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 11th Nov 2008 13:31 Edited at: 11th Nov 2008 13:32
Try this out

I've added some comments to explain what I changed

Edit: Tom beat me to it.


-> Oh, come on...
Jake025
16
Years of Service
User Offline
Joined: 28th Aug 2008
Location:
Posted: 11th Nov 2008 14:25
Thank you! That worked great!

Login to post a reply

Server time is: 2024-11-25 16:57:56
Your offset time is: 2024-11-25 16:57:56