slowing down a loop?
Blitz3D Forums/Blitz3D Programming/slowing down a loop?| 
 | ||
| Hi, is there a way to slow down a FOR/NEXT loop? I've tried several things like timers, but the only outcome is that my whole game gets paused. Anyway, I want it to set the gravity (falling speed) of the player starts at 0 and then count down to -100, yet at a rate I want. The LOOP is instantaneous. Here is my code : If Not EntityCollided(player,world_col) Then For i=0 To -100 Step -1 TranslateEntity player, 0,i, 0 Next EndIf Thanks! Edit : whoops, I saw I posted this in coding, while it is meant for the beginners area. my apologies... | 
| 
 | ||
| Use Delay. | 
| 
 | ||
| you should use timer, and then timer value to decrease/increase falling/jump..on that way you will control motion/time at once.. | 
| 
 | ||
| Also change this to make it more understandable: If Not EntityCollided(player,world_col) Then For i=0 To 100 TranslateEntity player, 0,-i, 0 Next EndIf | 
| 
 | ||
| You should NOT use delay in this situation or a loop.  Something like this should work. Set up a global VelocityY and const Gravity : global VelocityY# = 0 const Gravity# = 1 Only apply gravity if player has not collided with world : 
if entitycollided( player, world_col ) 
     VelocityY# = 0
else
     VelocityY = VelocityY - Gravity
     if VelocityY < -100 VelocityY = -100
endif
translateentity player, 0 , VelocityY, 0
 | 
| 
 | ||
| You run the whole loop as a loop inside the main game loop. Therefore it has to do the internal loop first (going from 0 to -100) Instead of a for loop, just decrease the players y coord by 1 in each main game loop and check if they get to y=-100 yet to stop them. | 
| 
 | ||
| Instead of a for loop, just decrease the players y coord by 1 in each main game loop and check if they get to y=-100 yet to stop them. Decreasing the players Y coord by 1 is going to simulate a constant downward velocity with no acceleration due to gravity. I don't think this is what he wants judging by his original code. | 
| 
 | ||
| You could use COS/SIN for an acceleration curve. Then you can work with a linear value, by inputting an angle into SIN/COS and it will produce an increasing/decreasing gap from the last number. ie: 0.001,0.002,0.005,0.013,0.04,0.1,0.4 etc etc | 
| 
 | ||
| Sounds interesting Ross, but still learning this and advanced maths is still a bit to much for me I think. However, Stevie's suggestion was exactly what I needed! Much appreciated! Thanks everybody! | 
| 
 | ||
|  You could use COS/SIN for an acceleration curve. Then you can work with a linear value, by inputting an angle into SIN/COS and it will produce an increasing/decreasing gap from the last number. ie: 0.001,0.002,0.005,0.013,0.04,0.1,0.4 etc etc that has to be the most complex way of applying gravity I've ever heard of. Why not simply watch my gravity tutorial on youtube: http://www.youtube.com/amcadam26 I explain it in a simple way there. [/shamless plug] | 
| 
 | ||
| Excellent! I've bookmarked it! |