Jumping...

Blitz3D Forums/Blitz3D Beginners Area/Jumping...

Happy Llama(Posted 2010) [#1]
I have a game were I am trying to make a camera jump. Pretty simple right? Here's the code when I press the space bar the camera just shoots into the air then drifts back to the ground. Is there any way to make it so the camera jumps up smoothly and drifts back down? TX!


Midimaster(Posted 2010) [#2]
While Not KeyDown (1)
   If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0
   ...
   CameraJump()
Wend


Function CameraJump()
   If KeyHit(2) Then
      StartJump=1
      CameraStartPos=EntityY(Camera)
   Endif
   If StartJump=1 then
      If EntityY(Camera)< CameraStartPos+20 Then
         MoveEntity Camera, 0, 0.5, 0
      Else
         StartJump=2
      Endif
   ElseIf StartJump=2 Then
      If EntityY(Camera)> CameraStartPos Then
         MoveEntity Camera, 0, -0.5, 0
      Else
         StartJump=0
      Else
         StartJump=2
      Endif
   Endif
End Function



Happy Llama(Posted 2010) [#3]
Thanks!


Nate the Great(Posted 2010) [#4]
copied from my tutorial...

its not 3d but it is more realistic looking and it is easy to convert

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.