Grandy Posted July 30, 2015 Share Posted July 30, 2015 Long story short, I need that platform to collide with another immovable object later, and immovable objects can't collide with other immovable ojects. I tried to make the player's gravity be equal to 0 when he is touching down, but that doesn't work. I tried to make his vertical velocity be zero when he is touching down, but that doesn't work. I tried to reverse it and make it so he only has velocity / gravity while NOT touching down (hey you never know), but no deal. If I could have both immovable sprites collide, it'd be ideal, but I could settle with a simple non-sinkable platform that isn't immovable. Link to comment Share on other sites More sharing options...
AzraelTycka Posted July 31, 2015 Share Posted July 31, 2015 Just curious, but when you set players gravity to 0 while he was touching down, did you change the velocity of your platform as well, afterall touching down means that the energy between the player and the platform were already transferred. (just in case add prerender function to your state - one of the basic functions in phaser similar to create, update, ...) and there set your level's velocity to 0 (or whatever it had before collision) and reset it to original position (height I guess if the platform was falling down due to contact with player) and set your player's height correctly as well (after touching it could be a few pixels below the platforms' top side). Btw if you want you can create a custom collision for this case or whatever gives you the problem, phaser allows this (well even if it didn't you could still do it). Grandy 1 Link to comment Share on other sites More sharing options...
Grandy Posted July 31, 2015 Author Share Posted July 31, 2015 Tried setting the velocity to 0 whenever he's touching down, didn't work. :/ The problem seems to be that the platform goes down even before the code registers Seems custom collision will be the way to go, then, though I'd still need to differentiate from which side it is colliding. Wait, hold the presses, I was messing around while writing this and it turns out the code works perfectly - but only if I make the player's gravity be equal to 1 when he touches down, instead of equal to 0. I think the problem is that when his gravity was equal to 0, the collision would push the platform very slightly down, and he'd be left in the air again, so his gravity went back to 600, so it fell down, so the platform would go slightly down, so etc. By setting his gravity to 1, he goes slightly down just as the patform goes slightly down, so he keeps touching down all the time instead of being left for a split second floating, so his gravity doesn't reset. I think. And the 1 gravity doesn't seem to be weight enough to push down the platform, so it all works out in the end. EDIT: Wait, I lie, he's still going down, but he's going down at a rate of 1 pixel by each 1.5 minutes, so.... Still annoying, but I don't think anyone would notice. EDIT2: And now when he is touching the platform, I made it have a reverse gravity of 1 as well, so they both cancel each other. Link to comment Share on other sites More sharing options...
Recommended Posts