I have a char which moves at (100*dt)pixels per update
this works fine in my laptop, because the dt average is 0.002, but in my desktop I get some conflicts, because the dt is around 0.01, which, multiplied by 100, turns into 1.
How can I solve this without slowing my character down?
framerate/dt problem
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: framerate/dt problem
It looks like you are calculating your character's position incorrectly - most probably, not using dt.
Can you put the code you are using here? At least the part that calculates the player movement.
Can you put the code you are using here? At least the part that calculates the player movement.
Last edited by kikito on Sun Feb 12, 2012 1:38 am, edited 1 time in total.
When I write def I mean function.
Re: framerate/dt problem
This is the function used to define the "target" x/y coordinates (it's a gridlocked system)
this is in the char:update() function
I don't know if it's understandable.
Also, the getFPS() function returns something around 400 in the laptop... is this normal?
Code: Select all
function actor:move(dir)
if dir == "up" then self.py = self.py - constants.base*constants.scale end
if dir == "down" then self.py = self.py + constants.base*constants.scale end
if dir == "right" then self.px = self.px + constants.base*constants.scale end
if dir == "left" then self.px = self.px - constants.base*constants.scale end
end
Code: Select all
if self.py == math.floor(self.y) and self.px == math.floor(self.x) then
if self.moveBogus ~= true then
self.moving = false
else
end
self.x = math.floor(self.x)
self.y = math.floor(self.y)
end
if self.px < math.floor(self.x) then
self.moving = true
self.state = 2
self.x = self.x - 100*dt-(self.running*dt*100)
elseif self.px > math.floor(self.x) then
self.moving = true
self.state = 3
self.x = self.x + 100*dt+(self.running*dt*100)
elseif self.py < math.floor(self.y) then
self.moving = true
self.state = 4
self.y = self.y - 100*dt-(self.running*dt*100)
elseif self.py > math.floor(self.y) then
self.moving = true
self.state = 1
self.y = self.y + 100*dt+(self.running*dt*100)
end
self.tx = self.px/(constants.scale*constants.base)
self.ty = self.py/(constants.scale*constants.base)
I don't know if it's understandable.
Also, the getFPS() function returns something around 400 in the laptop... is this normal?
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: framerate/dt problem
I don't quite understand what you are trying to achieve - don't know what self.px and self.py are trying to represent.
The problem could be here (in the 4 lines equivalent to this one, for each direction):
That code is equivalent to this one:
I don't know what self.running represents, but it looks wrong.
The problem could be here (in the 4 lines equivalent to this one, for each direction):
Code: Select all
self.x = self.x - 100*dt-(self.running*dt*100)
Code: Select all
self.x = self.x - (1+self.running)*dt*100
When I write def I mean function.
Re: framerate/dt problem
self.running represents wether the char is running or not. If its value is 1, it adds to the speed of the character, if it's 0, does nothing.
self.px and self.py are the "target" x and y coordinates for my gridlocking system. The "move" function sets them, and the "update" function gradually increases/decreases the real x and y coordinates so they match in the end.
The problem is, sometimes one of the coordinates gets stuck in a value like 129, and the update function repeatedly increases/decreases 100*dt to this value.
I'll post the full code here so you can check for yourself:
self.px and self.py are the "target" x and y coordinates for my gridlocking system. The "move" function sets them, and the "update" function gradually increases/decreases the real x and y coordinates so they match in the end.
The problem is, sometimes one of the coordinates gets stuck in a value like 129, and the update function repeatedly increases/decreases 100*dt to this value.
I'll post the full code here so you can check for yourself:
- Attachments
-
- myproj.love
- (1.37 MiB) Downloaded 369 times
Re: framerate/dt problem
BTW, the game doesn't run on my PC (windows).
I also tried 0.7.2, but it simply crashed.
========
Edit*
Remove those .lua and it works.
I also tried 0.7.2, but it simply crashed.
========
Edit*
Code: Select all
require("src/constants")
require("src/map")
require("src/actors")
require("scenes/game")
Re: framerate/dt problem
strange... it works fine here on 0.7.2/windows
anyone had the same problem?
looks like some issue with the / and \ characters... I used require("folder/file.lua") and it worked here
I changed a little bit of the code, see if it works now:
anyone had the same problem?
looks like some issue with the / and \ characters... I used require("folder/file.lua") and it worked here
I changed a little bit of the code, see if it works now:
- Attachments
-
- myproj2.love
- (1.37 MiB) Downloaded 342 times
Re: framerate/dt problem
It's working fine here OSX/0.7.2 (first version and second version)
Do you pretend to achieve a kind of animated turn-based movement (as in a roguelike like Dungeons of Dreadmor)?
Do you pretend to achieve a kind of animated turn-based movement (as in a roguelike like Dungeons of Dreadmor)?
Last edited by coffee on Sun Feb 12, 2012 3:43 am, edited 2 times in total.
Re: framerate/dt problem
Nah, it doesn't report error in 0.7.2, just crash, so I'm not sure what happened.
Although in 0.8.0 it works when if I remove those .lua.
Although in 0.8.0 it works when if I remove those .lua.
Re: framerate/dt problem
It will be an action-rpg, I just want the movement to stay locked on the 64x64 grid
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 9 guests