smooth and realistic physics movement

Hi,

I try to move my player with physics (applyForce/applyLinearImpulse) and the player is also affected by force fields from blowers etc.

Everytime the player hits the ground following funtion is called
[lua]function floorCollision(event)
if(event.phase == “began”) then
player:setLinearVelocity(0, 0)
player:applyLinearImpulse(0.55, -2.5, player.x, player.y)
end
end[/lua]

Everytime the player gets in a force field (invisible sensor) of a blower following code is called:
[lua]function BlowerCollision (Blower, event)
if (event.phase == “began”) then
local forceX = math.cos(Blower.rotation) * 10
local forceY = math.sin(Blower.rotation) * 10

event.other:applyForce(forceX, forceY, Blower.x, Blower.y)
end
end[/lua]

This codes works more or less but the movement is somehow strange. It is very snatchy and sometime the player jumps in the sky without any reason.

Is there a better way to provide realistic and smooth physic behaviour?

Any help is really welcome because this issue is really frustrating. I tried many different settings but nothing seemed to work better. [import]uid: 74852 topic_id: 12649 reply_id: 312649[/import]

The sky thing sounds like maybe he’s being effected by a large number of “blowers” or, if there is only one “blower”, that the event is called multiple times rather than just once.

For smooth physics you should test on your device; I have had physics from time to time look slightly off in the simulator but great on my phone.

If they really aren’t right you just have to adjust them a little, test, adjust more, etc. There’s no “just right” lot of physics settings, it depends on your game, objects, gravity, etc.

Peach :slight_smile: [import]uid: 52491 topic_id: 12649 reply_id: 46397[/import]

Thanks, so I’ll just keep adjusting ;). [import]uid: 74852 topic_id: 12649 reply_id: 46407[/import]

@gyrospeter - what peachpellen said, test, tweek, test. It’s cumbersome, but worth it to get it right.

One thing I’ve found when using applying LinearImpulse and Force is this… applyLinearImpulse I use for one time forces, it’s very “strong” compared to applyForce, so I use it for explosions etc. It is very jerky, and with strong impulses sometimes mucks with joints and what not.

applyForce is best used within a enterFrame handler, and it gradually applies the force from frame to frame, creating a smoother transition. Usually my code looks something like this:

[code]
local hero.BlowerCollision = function (event)
if (event.phase == “began”) then
hero.isInTheBlower = true
end
if (event.phase == “ended”) then
hero.isInTheBlower = false
end
end

–then in the enterFrame event handle

local hero.enterFrame = function (event)
if (hero.isInTheBlower) then
hero:applyForce(forceX, forceY, Blower.x, Blower.y)
end
end [import]uid: 29520 topic_id: 12649 reply_id: 46418[/import]

Thanks a lot, I’ll try your code tonight. [import]uid: 74852 topic_id: 12649 reply_id: 46426[/import]

@mudstuffing:

Mhh, I tried to implement you code but I’m new to corona and I don’t get it to work ;).

My problem is, that I have n-blowers (they are created dynamically) and so I can not use Blower.x etc.

How can I use the enterFrame-Event for n-blowers? [import]uid: 74852 topic_id: 12649 reply_id: 46433[/import]