From kinematic to static on collision

I’m trying to figure out how to make a platform go from kinematic to static once the player has passed through it, can someone please help me with this?

[import]uid: 34126 topic_id: 11536 reply_id: 311536[/import]

Sure

[lua]local function onCollision(self, event)

if (event.phase == “ended” ) then
self.bodyType = “static”
end
end

[/lua]

*nb in theory should work when you set up collision listener. This would change the sprite that the listener is set up on. To flip i think just change to event.other.bodyType. thats off top of my head:) [import]uid: 66324 topic_id: 11536 reply_id: 41858[/import]

Using kinematic objects to detect collisions is tricky.

You mention “once the player has passed through it”… do you mean like a one-way door?

Two thoughts - First, when a body is “kinematic” you have to set “isSensor=true”, to get it to respond to “collision” events.

Second, this documentation (from http://developer.anscamobile.com/content/game-edition-collision-detection ) might be helpful:


“preCollision”: an event type that fires right before the objects start to interact. Depending on your game logic, you may wish to detect this event and conditionally override the collision.

For example, in a platform game, you may wish to construct “one-sided” platforms that the character can jump vertically through, but only in one direction. You might do this by comparing the character and platform position to see if the character is below the platform, and then using a short timer to make “isSensor” body property temporarily true for the character object so that it passes through the platform. If you do not implement a “preCollision” listener, this event will not fire.


[import]uid: 18951 topic_id: 11536 reply_id: 41904[/import]

@eieiosoftware

I’m just trying to make a doodle jump clone but it seems to very difficult to make the platforms interact with the player.

I tried to change so the “platform.isSensor = true” until the player has passed through then set it to false but it didn’t work so I ended up with all platforms being static so the player had to jump around them.

Another issue was the continuous jumping, I tried to make that with collision also and apply linear impulse when the player hit the platform but instead the player started jumping like crazy.

I had set the linearImpulse to player.height*4.

Then after a while I read that the platform player collision was very difficult to create so I gave up on my project but now after some time has passed, I can’t get it out of my head and I just NEED to learn how to do it

So maybe Ansca could make a doodleJump sample? [import]uid: 34126 topic_id: 11536 reply_id: 41918[/import]

http://developer.anscamobile.com/forum/2011/05/27/platformer-doodle-jump

this link may help? Tom at Ansca seems to outline a solution … only skimmed it

Ooops just noticed u were already part of that thread:| [import]uid: 66324 topic_id: 11536 reply_id: 41922[/import]

if you don’t want the player to ever be able to stand still (keep jumping at a certain height), try applying bounce to the platforms instead of a force to the player. It will be like the player is in a “bouncy world.” You’ll have to play with the values. And I’d use the one sided collision using perCollision listener to determine if the player’s Y value is less than the platform’s. If it is, the player can pass through. I haven’t written this into any of my code yet, but the example I sighted above is what I plan to try in my next project.

–edit–
I just re-read what I wrote and realize it is really over-simplified. Like I said, I have never used this functionality. When I get a free minute, I’ll try to throw together an example. [import]uid: 18951 topic_id: 11536 reply_id: 41926[/import]