I have a big problem with applyLinearImpulse()
I’m working on classic platform game.
My hero jump’s height depends on how long the “JumpButton” is pressed.
So, I use this code:
local function f_jump(event)
hero:applyLinearImpulse(0,-0.04,hero.x, hero.y)
–
JumpCounter = JumpCounter + 1 --for test only
if JumpCounter == 11 then
print(BeforeY - hero.y)
end
end
function JumpButtonTouch(event)
if (event.phase == “began”) then
JumpTimer = timer.performWithDelay( 15, f_jump, 11 )
JumpCounter = 0
BeforeY = hero.y --for test only
hero:applyLinearImpulse(0,-0.04,hero.x, hero.y)
else
if JumpTimer then timer.cancel(JumpTimer) end
end
end
JumpButton:addEventListener(“touch”, JumpButtonTouch )
I use a little impulse max. 12 times.
It works, but I can see two big problems:
1.
I print jump’s height just befor last impulse. And I can see that my hero sometimes jumps lower! Why?
I can read in Simulator Output:
35.316558837891
35.316558837891
35.316558837891
30.878707885742
35.316558837891
30.878707885742
30.878707885742
35.316558837891
35.316558837891
35.316558837891
35.316558837891
30.878707885742
35.316558837891
2.
The jump is much slower on my real machine (low-end Android tablet 1GHz) than on the Simulator. I changed gravity and physics’s scale but on real machine jump is always much slower.
I have a hypothesis: FPS is 60 in config.lua but I verified that framerate on my tablet varies from 35 to 42fps. All my game’s engine works good regardless of fps.
Is it possible that applyLinearImpulse() or all physics engine works slower when fps is low?
EDITED: I set fps to 30 in config.lua and now jump’s height and time changed even in Simulator! How is it possible?