Re: One Way To Go
Posted: Tue Jan 03, 2012 4:44 pm
I always give the dentist my raw, unadulterated stagnant fumes.kikito wrote:Kindof similar to brushing up your teeth between eating smelly cheese and going to the dentist.
I always give the dentist my raw, unadulterated stagnant fumes.kikito wrote:Kindof similar to brushing up your teeth between eating smelly cheese and going to the dentist.
I think the problem is somewhere else then. Why don't you just upload the whole .love file?gordebak wrote:Actually I use velx and vely. I just wrote it here incorrectly.
Edit: Corrected the code.
Code: Select all
--somewhere, when the speed is set
velx = 200 -- pixels per second
--and the starting x position of your object
x = 15
--in update
x = x + velx*dt -- it moves 200 pixels per second, so after 1 second it will be at 215
That's what I do in the code. It works fine, but velocity changes from time to time. Especially after changing direction.bartbes wrote:Anyway, robin explained it well, you define your speed as pixels per second, then multiply it by dt (every frame) to get the distance traveled between the frames.
So:EDIT: Of course there is the risk that I've misunderstood and you're past this stage.Code: Select all
--somewhere, when the speed is set velx = 200 -- pixels per second --and the starting x position of your object x = 15 --in update x = x + velx*dt -- it moves 200 pixels per second, so after 1 second it will be at 215
But velx = difficulty * dt in this case. To be exact, x = x + (difficulty * dt). So it must be the same as what you said, right?MarekkPie wrote:The relative velocity (the velocity at each call) will change. But when you sum the displacement between your position at t = 0 and your displacement at t = 1, it will equal your velocity in pixels/second.
If you simply go, x = x + velx, then your velocity is in pixels/dt, which is 1/dt times faster than the above.
I think this is where you are getting the perception of a speed increase/decrease. If you just print(velx * dt) then it will look like a speed change. Just remember that isn't really the case.
I hope I have that math right. My brain hurts today.