Moving through Physics objects

I have a floor and a player object.

The floor is a “static” physics body.
The player is a “Dynamic” physic body.

When the player lands on the floor he’ll land on it. (He can also jump when you press a button! :O)

The thing that’s confusing me is I want him to be able to jump through ‘floor’ physics objects.

My idea on how to achieve this was to ‘getLinearVelocity’ and check if it was > 0 (Which basically checks if he’s jumping.)
Then if he is, he goes through.

But at the minute he hit’s his head.
I’m not sure how to make him temporarily pass-throughable.
Or perhaps make him always pass-throughable, I did try making him "Kinematic"but then I couldn’t figure out how to get him to run on top of a floor when he’s landed. He’ll just drift through it.

Haha
Is this possible with the Corona built in physics? [import]uid: 91798 topic_id: 29640 reply_id: 329640[/import]

What i understand from what u say,

You can try this:

Get players velocity inside collision function’s began phase: like vx and vy

if vy<0 then
Player is landing, u may want to make player unsensor etc

elseif vy>0 then
Player is jumpin, u may want to make player sensor, so he may pass through.

May be, ur player has multiple physics body?

[import]uid: 147582 topic_id: 29640 reply_id: 118980[/import]

Doing this causes quite a few issues.

Firstly, the world is locked and can’t change anything with addBody while ‘number crunching’

To solve this I put the physics change on a small timer using timer.performWithDelay(1,waitphysics)
And it sort of worked, But very badly.

My player was sinking halfway into the floor then juttering around and sometimes he’s pop out the side.
It was pretty bad.

I’m kind of just thinking of a platformer where you can jump up and down layers of floor y’know.

I found a great website which goes through the ideas behind different platformers.
The kind I’m wondering about is the ‘One-Way Platformers’
It’s pretty decent at summarizing the requirements.

http://higherorderfun.com/blog/2012/05/20/the-guide-to-implementing-2d-platformers/

**"One-way platforms are platforms that you can step on, but you can also jump through them. In other words, they count as an obstacle if you’re already on top of them, but are otherwise traversable. That sentence is the key to understanding their behavior. The algorithm changes as follows:

On the x axis, the tile is never an obstacle
On the y axis, the tile is only an obstacle if, prior to the movement, the player was entirely above it (that is, bottom-most coordinate of player was at least one pixel above top-most coordinate of one-way platform). To check for this, you will probably want to store the original player position before doing any stepping.

It might be tempting to have it act as an obstacle if the player’s y speed is positive (that is, if the player is falling), but this behavior is wrong: it’s possible for the player to jump so he overlaps the platform, but then falls down again without having his feet reach the platform. In that case, he should still fall through."**

[import]uid: 91798 topic_id: 29640 reply_id: 118985[/import]

i’m noob in corona, but i think this link will helps you
http://developer.coronalabs.com/reference/index/bodyissensor

some help maybe

box=player

local function onLocalPreCollision( self, event )
– Let box pass through platform 1
local platform = event.other
if platform.myName == “platform1” and player.y > platform.y then
platform.isSensor = true
–your player jump through your floor
else
platform.isSensor = false
–your player will land on your floor
end
end
player.preCollision = onLocalPreCollision
player:addEventListener( “preCollision”, player) [import]uid: 160941 topic_id: 29640 reply_id: 118991[/import]

I’m going to bed now.

You’ve given me a lot to think about while I DON’T get to sleep :stuck_out_tongue:

preCollision is an interesting idea.
And the overall Idea seems great. Turning the platform into a sensor and back again.

(I was trying to do this to my character but I was trying to do it from the physics.addBody() area. By removing the body and re-adding it, It worked but Badly as I’ve said.)

But doing it that way seems like a lot better.

My only concern is that my game is a tile based game so there are loads of little cube individual platforms. My concern is that it’s lag to hell and back turning them to sensor.
But I should be able to only turn the platforms the character touched/ near the player or possibly on screen off.

Or maybe I can adapt it to the player turns into a sensor.

Like I said you’ve given me a lot to think about here. ^-^

I’m not wanting a reply just yet, I’m just letting you know, cause I won’t reply for I’ll be in the land of nod!

Thanks,
Matt [import]uid: 91798 topic_id: 29640 reply_id: 118992[/import]

Okay!

We’ll implementing the advice from nyoman.sony, was helpful but, as you often do, I came up against an issue. Not with that piece, mind you.

My character can now jump through ground pieces and land on them too.

My main issue is:
On the x axis, the tile is never an obstacle

I’ve been able to half figure this out but not fully. IF my characters jumping upwards (vy >0) then they can remain as sensors, but if he’s falling, he might land on one so I can’t use (vy<0).
The reason being, I don’t want him to get stopped by a tile if he runs into it sideways.
(As it’s an runner game and I don’t want him pushed off screen.)

My thoughts stray to keeping the the floor sensors by checking the bottom of my character against the top of the floor.
The character needs to be 1 pixel above the floor to land so anything under should not even bother checking.
That would involve some x1, x2, y1, y2.
Is this a viable way to achieve this? This is looking harder than expected.
Another issue I had was that if I jumped through a piece, the preCollision marked that as ‘isSensor = true’ meaning I could jump through, but if I landed on the same piece It wouldn’t do another preCollision and thus never changed it back to ‘isSensor = false’.

It seems like the preCollision only runs once per physics object?
[import]uid: 91798 topic_id: 29640 reply_id: 119151[/import]