I am applying linearimpulse to my player while jumping from static platforms. But I am facing a problem that the player gets stuck midair after the impulse, it seems the gravity is not getting applied to it somehow.
My player setup look like this:
physics.start()
physics.setGravity(0, 15)
When the box becomes blue, it meas it is “idle” and the physics engine stop making calculations on this.
This makes sense form the point that an object will never move or apply forces by itself without any external stimulation.
I am not used to use the Solar2D physics, so I do not know what is the best way to do what you are doing. But you have to apply a force to your box instead of your environment.
I think that moving your group to the left on each enterFrame and counteracting that by applying an horizontal force to your box to keep it moving would work.
This would be the code
local prevTime
local speed = -0.1
function scene:enterFrame(e)
local timeElapsed = system.getTimer() - prevTime
prevTime = prevTime + timeElapsed
self.view.x = self.view.x + speed*timeElapsed
local vx, vy = box:getLinearVelocity()
if vx < .1 then
box:setLinearVelocity( .1, vy )
end
end
If you don’t take the mass into account, and later decide to make the ‘hero’ bigger or smaller, your impulse response will suddenly stop behaving the way it used to which can be a real pain.