I have been trying to get that basic effect of passing through a platform underneath and then bouncing on top of it. I have been trying for about a day now, and still not there. I have found various different solutions online, but none of them have worked, including the one in the documentation (several people are complaining of it not working).
I have tried the following:
- Use a preCollision and check for the y coordinates of the moving object, if it’s higher (making it below) then make the platform a sensor so he can pass through. If the moving object is above the object then isSensor is set to false, causing a collision. I have a listener for onCollision that makes my character jump.
This doesn’t work. My character never passes through the platform, whether he’s coming from above or below. The code for this is here: http://pastebin.com/VcidWAvW
I’ve also tried (found a thread on the forums of someone having the same issue):
- Use a preCollision as before and detect placement of character. This time, the platform is always a sensor. I then have a ‘hard’ (isSensor=false) platform off screen that is the same size as the sensor platform. When the moving object/character is coming downwards I detect on a preCollision and move the hard platform in place so it hits that instead. If it comes from below then I move it off screen.
This worked the same as above, and wouldn’t pass through at all.
I then tried setting the event to a collision, instead of preCollision. This worked far better, but occassionally the character doesn’t pass through. The character would also get stuck against the side of the platform - this is rare but does happen (potentially a bug I can live with). The code for this is here: http://pastebin.com/fXJDvbNf (please note: I added a second listener ‘movePlatform’, I read on another forum post that you can’t directly manipulate objects on a collision event, so instead O set a flag and check for this flag on enterFrame).
Any help is appreciated. I know I’m not the only one struggling on what should be a simple concept, I have read quite a lot of forum posts on this, but no positive answers.
Thanks [import]uid: 61422 topic_id: 15399 reply_id: 315399[/import]
[import]uid: 61422 topic_id: 15399 reply_id: 56899[/import]