smooting for jumping
Blitz3D Forums/Blitz3D Beginners Area/smooting for jumping
| ||
ok yes i know i've posted about jumping before but this is different because i have the jumping done it's just once the camera gets to a certain point it comes back down like it hit a barrier and i no y it does that i just want it to be smoot like a real jump you know, here is my code; press spacebar to jump If KeyHit(57) And falling = False jumped = True EndIf If jumped = True yvel# = yvel# + .6 ; if the player is at highest point, start moving down If yvel# >= 6 jumped = False EndIf EndIf ; start the falling process yvel# = yvel# - .3 If yvel# <= 0 yvel# = 0 falling = False EndIf |
| ||
If you follow my example from your other post where you posted the same problem it'll work fine. http://www.blitzbasic.com/Community/posts.php?topic=42453 |
| ||
Use Cos for you jumping :o) Basically, when the jump is rising upwards, have a variable and add one to it. When the jump is falling, suntract a value from it. Then, plug this into something like:moveentity player,0,cos(jump_value),0 Since Cos is a mathimatical wave, it will form a smooth jumping motion. Here's some code for it: Graphics3D 800,600 SetBuffer BackBuffer() Global camera = CreateCamera() PositionEntity camera,0,0,-10 Global light = CreateLight() Global cube = CreateCube() Global jump_value = 0 Global jump_flag = 0 While Not KeyHit(1) If KeyHit(200) And jump_flag = 0 Then jump_flag = 1 End If If jump_flag = 1 Then MoveEntity cube,0,Cos(jump_value)/10,0 jump_value = jump_value + 2 If jump_value >60 Then jump_flag = 2 End If ElseIf jump_flag = 2 Then MoveEntity cube,0,-Cos(jump_value)/10,0 jump_value = jump_value - 2 If jump_value < 0 Then jump_flag = 0 jump_value = 0 End If End If UpdateWorld RenderWorld Flip Wend End |
| ||
ok Rob i tried yours but it doesn't round off like it does in yours but that might be because it is different in 2d and Ross yours is just doin what mine already does which is falling as soon as it reaches the point and i want it to jump like halo you know when you jump and it gets to the highest point it kinda rounds off insead of just instantly going down |
| ||
Well, change the value at which the jump flag is changed... this line...If jump_value >60 Then change it to 70 80 or even 90. |
| ||
2d or 3d makes bugger all difference. Ross' example will fail if you're jumping from a high point to a low point. |
| ||
Yeah, i realise that :o) Just to demonstrate the use of Cos for jumping :o) |
| ||
The example I posted in your other thread gave smooth jumping without cos/sin for exactly the reason given by Rob. |
| ||
Well, you cap the angle applied into Cos, say at 70, the point where he no longer accelerates downwards. It was just a quick example. |