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.

Dark GDK / need help with jumping

Author
Message
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 21st Jul 2009 03:29
im making a sidescrolling game similar to mario and i was wondering how to get the character to jump i have it to where if you hold the button down he keeps going up and he falls if you release it. but i want him to fall after a certain amount of time whether your still holding the key down or not
Bubzy
15
Years of Service
User Offline
Joined: 29th Jun 2009
Location: somewhere
Posted: 21st Jul 2009 13:09 Edited at: 21st Jul 2009 21:10
Duplicate Post

void void void void void void void
Bubzy
15
Years of Service
User Offline
Joined: 29th Jun 2009
Location: somewhere
Posted: 21st Jul 2009 13:21
i guess a complicated way of doing it would be to store the players position before he left the ground and then perform a check on his current height difference from the ground position and when that reaches a certain value to stop the increment.


i think this will work. but im fairly new to c++ and i havent got a chance to compile or test this

void void void void void void void
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 21st Jul 2009 20:59
ok thanks ill try that
randal
15
Years of Service
User Offline
Joined: 18th Nov 2008
Location:
Posted: 22nd Jul 2009 15:57
why not try using some basic physics?

give your character an up/down velocity eg. float velocity = 0.0f

then when you press the jump button: velocity += 10.0f;

position the character to its current yPos + velocity;

decrement the velocity by earth gravity eg. velocity -= 0.98f

if the character is back on the ground set velocity to 0.0f

only check for the jump input key if the velocity equals 0.0f
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 26th Jul 2009 04:35
i tried that but when i push the jump button he just goes up the amount of the vertical velocity and doesnt fall back down
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 27th Jul 2009 19:47 Edited at: 30th Jul 2009 01:52
now i have a new problem, i got the basic jumping working but the starting y position of my character is 256 and when he jumps if the top of his jump is less than 200 he floats to the top of the screen and stays.
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 31st Jul 2009 20:49
sorry for the triple post but it wont update when the last post was made
Necro_100000
15
Years of Service
User Offline
Joined: 31st Jul 2009
Location:
Posted: 31st Jul 2009 22:12
What function are you using? Are you using the Basic physics that Randal implied?

if so make sure that you don't have any code that effects the velocity after you've jumped besides the gravity.

Try splitting up your code into a header or another c++ or apply it in another game to see if it's your jump code OR if it's something in your code causing the error.

If you could post some source code I could maybe take a look at it, but I can't really tell what would cause your problem from your response.
Bubzy
15
Years of Service
User Offline
Joined: 29th Jun 2009
Location: somewhere
Posted: 1st Aug 2009 00:47


its really scrappy and could use some tidying up but give it a go, the principles are there.

void void void void void void void

Attachments

Login to view attachments
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 1st Aug 2009 01:49
Here's a program that works fine



you would just substitute the



to



New Site! Check it out \/
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 1st Aug 2009 22:15 Edited at: 1st Aug 2009 22:29
here's my source code its pretty messy right now i cant find out what the problem is


and any other help or tips would be appreciated. and also does anyone know if there is a plug in for 2d collision?
Bubzy
15
Years of Service
User Offline
Joined: 29th Jun 2009
Location: somewhere
Posted: 2nd Aug 2009 01:19
its kinda bad practice to reinitialise variables that you are using in a loop.




ok lets look at it another way




**UNTESTED** this should work. try not to overcomplicate your code you used 3 numbers to indicate a jumpstate when really only a boolean value was required. Post again if you need more help or if ive crapped this code up

void Void(void){(for i = 0; i < i+1; i++){cout<<"bubzy rules "};}
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 2nd Aug 2009 01:42
ok thanks ill give that a try when i get home later
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 4th Aug 2009 20:54
@ Bubzy

that worked for the most part but now when i hold down the jump button he floats at the top of the jump

Login to post a reply

Server time is: 2024-10-01 10:40:43
Your offset time is: 2024-10-01 10:40:43