Hello.
I have a problem when using physics objects together with the ultimate config.lua file.
The problem is that when I use the ultimate config file and apply a linear impulse to an object, the object travels different distances for different devices. I tested it with Corona simulator.
Attached to this post there is a sample project I made to demonstrate this problem. When open, click on the circle and watch the Simulator output and see how far it has traveled. Then change the device type and repeat the process and see that the distance traveled is not the same.
When I used the default config file when a new project is created this was not an issue. The distance traveled was constant across multiple devices.
In the attached project the config.lua file is the ultimate one, and for test purposes the config_default.lua file is the default one. In case any of you might want to test this out.
What I figured so far is that when using the ultimate config file the screen resolution is not the same and this affects the calculated mass of the object and therefore the impulse has different effects on the object.
I think that by using a dynamic value for the density or the impulse (or both) of the object I might make it behave properly, but I have no idea how.
Any help or hint is appreciated. Thank you.
For convenience I will paste the code in the attachment here too:
local physics = require("physics") physics.start() local appWidth = display.contentWidth local appHeight = display.contentHeight local appUnitX = appWidth/20 local playDt local runtime = 0 local objRadius = appUnitX local impulseX = 100 local impulseY = -100 local objDensity = 5 local function launchTestObj(event) physics.addBody(event.target, {density=objDensity, friction=0.0, bounce=0.0 } ) event.target:applyLinearImpulse( impulseX , impulseY, event.target.x, event.target.y ) -- prints some info print("width:" .. appWidth .. " height:" .. appHeight .. " density:" .. objDensity) print("mass:" .. event.target.mass .. " impulseX:" .. impulseX .. " impulseY:" .. impulseY) end local testObj = display.newCircle(0, 0, objRadius) testObj.anchorX = 0.5; testObj.anchorY = 0.5 testObj.x = 0;testObj.y = appHeight testObj.stopPhysics = false -- to remove physics object only once testObj:addEventListener( "tap", launchTestObj ) local function getDeltaTime() local temp = system.getTimer() --Get current game time in ms if runtime == 0 then runtime = temp-33.33 end -- force the dt to be 1 for the first frame local dt = (temp-runtime) / (1000/30) --60fps or 30fps as base runtime = temp --Store game time return dt end local function frameUpdate() --Delta Time value playDt = getDeltaTime() if testObj.y \> appHeight and testObj.stopPhysics == false then testObj.stopPhysics = true physics.removeBody( testObj ) print("distance (measured in appUnitX): " .. (testObj.x/appUnitX)) end end Runtime:addEventListener( "enterFrame", frameUpdate )
I got the config file from this tutorial:
http://coronalabs.com/blog/2012/12/04/the-ultimate-config-lua-file/