framerate/dt problem

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
xeol
Prole
Posts: 22
Joined: Thu May 19, 2011 7:12 pm
Location: Ipatinga, Brazil

framerate/dt problem

Post by xeol »

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?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: framerate/dt problem

Post by kikito »

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.
Last edited by kikito on Sun Feb 12, 2012 1:38 am, edited 1 time in total.
When I write def I mean function.
User avatar
xeol
Prole
Posts: 22
Joined: Thu May 19, 2011 7:12 pm
Location: Ipatinga, Brazil

Re: framerate/dt problem

Post by xeol »

This is the function used to define the "target" x/y coordinates (it's a gridlocked system)

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
this is in the char:update() function

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?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: framerate/dt problem

Post by kikito »

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):

Code: Select all

self.x = self.x - 100*dt-(self.running*dt*100)
That code is equivalent to this one:

Code: Select all

self.x = self.x - (1+self.running)*dt*100
I don't know what self.running represents, but it looks wrong.
When I write def I mean function.
User avatar
xeol
Prole
Posts: 22
Joined: Thu May 19, 2011 7:12 pm
Location: Ipatinga, Brazil

Re: framerate/dt problem

Post by xeol »

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:
Attachments
myproj.love
(1.37 MiB) Downloaded 353 times
utunnels
Citizen
Posts: 75
Joined: Fri Jan 06, 2012 5:20 pm

Re: framerate/dt problem

Post by utunnels »

BTW, the game doesn't run on my PC (windows).

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")
Remove those .lua and it works.
Attachments
err.png
err.png (16.52 KiB) Viewed 4989 times
User avatar
xeol
Prole
Posts: 22
Joined: Thu May 19, 2011 7:12 pm
Location: Ipatinga, Brazil

Re: framerate/dt problem

Post by xeol »

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:
Attachments
myproj2.love
(1.37 MiB) Downloaded 324 times
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: framerate/dt problem

Post by coffee »

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)?
Last edited by coffee on Sun Feb 12, 2012 3:43 am, edited 2 times in total.
utunnels
Citizen
Posts: 75
Joined: Fri Jan 06, 2012 5:20 pm

Re: framerate/dt problem

Post by utunnels »

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.
User avatar
xeol
Prole
Posts: 22
Joined: Thu May 19, 2011 7:12 pm
Location: Ipatinga, Brazil

Re: framerate/dt problem

Post by xeol »

It will be an action-rpg, I just want the movement to stay locked on the 64x64 grid
Post Reply

Who is online

Users browsing this forum: No registered users and 80 guests