When to use delta timing...
Monkey Forums/Monkey Programming/When to use delta timing...
| ||
I've got a bit of code and I think I am doing too much delta timing on it. Here is the code without any delta timing: if dx > 0 if height <> 0 dy += 0.3 angle += amount End height += dy if height > 0 height = 0 amount = 0 dx *= .5 dy = 0 - (dy * 0.4) if dy >-1 dy = 0 height = 0 End End if dy = 0 dx -= 0.010 End x += (Sin(angle) * dx) y += (Cos(angle) * dx) end I had delta timing everytime I added/multipled/subtracted... and now I am confussed even more :( So where should I use delta timing in this code? |
| ||
You should only need it on the two sin and cos lines at the end otherwise you'll be applying delta multiple times and end up with weird results. also you have dx on the cos line and it should be dy. |
| ||
Thanks Dave... thats what I thought but it still wrong: Using Jame's delta timing example, press left and right cursor keys to alter the framerate. The green ball has delta timing. |
| ||
This looks better:if dx > 0 if height <> 0 dy = dy + 0.3 * delta angle = angle + amount * delta End height = height + dy * delta if height > 0 height = 0 amount = 0 dx = dx / 2 dy = 0 - (dy * 0.4) if dy >-1 dy = 0 height = 0 End End if dy = 0 dx -= 0.030 * delta End x = x + Sin(angle) * (dx * delta) y = y + Cos(angle) * (dx * delta) end |
| ||
I think you only need to do it on the last couple of lines as someone mentioned. Try removing all the delta's and use something like. Local velocityX:Float = Sin(angle) * dx Local velocityY:Float = Cos(angle) * dx ' you use dx here in your code are you sure this isn't supposed to be dy? x = x + (velocityX * delta) y = y + (velocityY * delta) You might need to play with your numbers though. The idea is that only when you move your player do you need to use your delta. So for example, say you wanted him to move 10 pixels per second then velocityX should be 10. You mulitply this value when you add it on to X so if 1 second had passed between the last frame and this one you'd jump 10 pixels. If 0.5 of a second had passed you'd move 5 pixels. |
| ||
Thanks luggage, yeah normally it would be fine to add the delta to just the movement variables - but this is slightly different. I am trying to get a ball moving around the screen that looks a bit like Sensible Soccer eg 2d but when the ball is in the "air" you can see the shadow. Have a play with the code in post #4. |
| ||
I can dig out the code to my Simple Soccer game if you like? http://www.gingerbeardman.com/archive/soccer/ try the early bird download (PC only) |
| ||
I can dig out the code to my Simple Soccer game if you like? That would be cool - Cheer Matt! |
| ||
I'd be interested to know what you have planned! ;)Type BallType ; The Ball Object Type. Field x#,y# ; Ball X and Y co-ords. Field z ; Ball Z-coord. Field dx#,dy# ; Ball X and Y direction increments Field dz ; Ball Z increments Field frame ; The current ball frame. End Typeproperties should be self explanatory Function draw_ball(posx, posy) ;sensi style shadow DrawImage bmp_ball, posx+ball\z, posy, 4 ;sensi style ball DrawImage bmp_ball, posx, posy-ball\z, Abs(Int(ball\frame/5) Mod 4) End Functionshadow is drawn with z property affecting x co-ordinate, ball is drawn with z affecting y co-ordinate. This gives the effect of "3D" ball movement in 2D. I guess this means lighting source is exactly West in direction? I know Croteam's football games on the Amiga used multiple lighting sources and therefore had multiple ball shadows (which was a bit OTT and confusing for me). http://hol.abime.net/hol_search.php?N_ref_developer=123 Hope that helps! |
| ||
Cool - can you show me how you move the actual ball? |
| ||
Just checked and I don't use delta timing at all.;move ball in x and y directions ball\x=ball\x+ball\dx ball\y=ball\y+ball\dyplus some friction/dampening applied each frame, and a check to clamp the speed to zero if it's close enough. |
| ||
This is a topic on blitzbasic.com from 2006 where Grey Alien asks whether to apply delta time to the value by which the acceleration itself is changed: http://www.blitzbasic.com/Community/posts.php?topic=61530 |