Jumping?

Blitz3D Forums/Blitz3D Beginners Area/Jumping?

Cubed Inc.(Posted 2010) [#1]
It's been awhile since my last post, which is a good thing:), but I have a question.
Does anyone know how I can add smooth jumping into the code below

please reply,thanks


Midimaster(Posted 2010) [#2]
look at this, but replace "camera" with "player":

http://www.blitzbasic.com/Community/posts.php?topic=90543#1029574


Nate the Great(Posted 2010) [#3]
Copied from my tutorial entry...

Hey

I have seen many people ask how to make things fall like they do in real life. I can only assume they are tired of making things fall at a few pixels per second. Well here is a nifty trick that I discovered when I made my first platformer game and soon figured out I wasnt the only one that knew this.

So here is how you do it step by step.

1. When you make a character or anything that will be affected by gravity give it a variable called velocity_y or vy.. whatever you want to call it

Main loop

2. If the object hit the ground then velocity_y = 0
3. Add velocity_y to the y value.
4. velocity_y = velocity_y + gravity
where gravity is a constant usually floating point variable.
gravity should be positive in 2d and negative in 3d

End of Main loop

This works for 2d and 3d!
to make an object jump set velocity_y to some bigish number in 3d it is positive, in 2d it is negative.

simple example:

Graphics 800,600,0,2

SetBuffer BackBuffer()

ballx# = 200
bally# = 200
ball_velocity_y# = 0

gravity# = .1
bounce# = .5

While Not KeyDown(1)
Cls
	ball_velocity_y# = ball_velocity_y# + gravity
	bally = bally + ball_velocity_y
	If bally# > 590 Then
		ball_velocity_y = -ball_velocity_y*bounce
		bally = 590
	EndIf
	
	Oval ballx,bally,10,10
Flip
Wend
End

this one even has bounce. set bounce to 0 to see it just stop like a normal character would.


Cubed Inc.(Posted 2010) [#4]
well, I don't want to sound like a lazy copy and paste coder, but can someone show me and example? As far as I've tried, I have created a constant named GRAVITY# and I set the variable to -.5, then in the games main loop, I translated the main character's y velocity with the gravity constant. That is all that I have for the jumping, so if someone knows a code for smooth jumping and falling, can you maybe show me the code and explain the steps so I can understand it better?


Nate the Great(Posted 2010) [#5]
I posted code, I just typed the codebox thing wrong... fixed


Cubed Inc.(Posted 2010) [#6]
Nate the Great
your code example is good and really realistic, but it's more of physics for basketballs rather than a person or character. I'm trying to figure out how to make my character jump like in a platform/action adventure game(Ratchet and Clank, psychonauts). thanks for trying to help anyways


Cubed Inc.(Posted 2010) [#7]
I found an example on how to do smooth jumping. I implemented the smooth jumping code into mine and I was able to make my character jump by pressing space:) but theres a problem. The camera keeps on slowely turning downwards. Why does it do this?
Here's my code with the smoothly implemented jumping

what's the problem? please reply, thanks


Nate the Great(Posted 2010) [#8]
your code example is good and really realistic, but it's more of physics for basketballs rather than a person or character. I'm trying to figure out how to make my character jump like in a platform/action adventure game(Ratchet and Clank, psychonauts). thanks for trying to help anyways


im not trying to argue but set the bounce to 0 and its perfect for characters. and your example uses the exact same principle except it sets the velocity to zero when it hits the ground... ;)


Cubed Inc.(Posted 2010) [#9]
Nate The Great
So your saying that the problem with my code is that I set the velocity to zero instead of the gravity? The code that I used would be perfect for the jumping but like I said before, when I put the code in, the camera just kept on slowely tilting downwards. The speed that the camera tilts downwards has to do with the level of the gravity. I set the gravity to .01 and the camera very slowely tilted downwards, but when I set the gravity to .1, the camera tilted down quickley. Why does it do this?!!!?!?!


Nate the Great(Posted 2010) [#10]
no, I was saying you were doint the exact same thing as me, but instead of a bounce variable you have it set to zero which as I said is perfect for characters. Sorry I dont know what is wrong with your camera. :/


GIB3D(Posted 2010) [#11]
The problem with the camera from my experience (I've only read what you said, not looked at any code of yours) is that if you're pointing the camera at the player, point the camera at the player before the gravity is applied or after the player is settled into the ground or else the camera will think the player is in a different place.