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.
One Way To Go
Re: One Way To Go
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: One Way To Go
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.
When I write def I mean function.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: One Way To Go
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.
So:
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
Re: One Way To Go
Here it is.
Edit: Sorry, the code is a bit ugly.
Edit: Sorry, the code is a bit ugly.
- Attachments
-
- one way to go - dt.love
- (1.85 MiB) Downloaded 339 times
Last edited by gordebak on Tue Jan 03, 2012 5:15 pm, edited 1 time in total.
Re: One Way To Go
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
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: One Way To Go
I haven't checked the code, but I think it's not dt.
Your speed is faster when you hold the arrow keys than when you release them. That explains how it changes after changing direction.
Your speed is faster when you hold the arrow keys than when you release them. That explains how it changes after changing direction.
Help us help you: attach a .love.
Re: One Way To Go
I checked the game on another computer, and it works fine. It seems that it's a hardware problem on my side.
Re: One Way To Go
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.
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.
Re: One Way To Go
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.
-
- Prole
- Posts: 8
- Joined: Tue Sep 21, 2010 8:27 pm
Re: One Way To Go
This is quite a lot of fun! Kudos.
My only niggle is that the music can get repetitive.
My only niggle is that the music can get repetitive.
Who is online
Users browsing this forum: No registered users and 3 guests