So I have a platformer. And it has good floor detection. I never fall through the floor. But landings are always a little unpredictable. I never land exactly at the same height on a level surface. I might land at the very tip top. Or I might touch down slightly lower before it registers. Anyway I can make it more exact/uniform?
I use a sensor sprite at the bottom of the player's sprite to find the floor. Basically this is what it looks like:
forever if <<touching [ground_l]> or <touching [ground_r]>> if <jumping = 0> set [grounded] to 1 if <grounded = 1> set [y velocity] to 0 end end end end
forever set x position to <[x position] of [playersprite]> set y position to <<[y position] of [playersprite]> - 16> endY velocity is like the gravity. If grounded = 0 (which means the sprite isn't on the floor) it's set to around -5/6, just to clarify.
Last edited by dusty22 (2013-04-05 17:56:11)
Offline
You could make it so as soon as the sprite touches ground, make a bunch of "if" s that move it up one pixel:
forever if <touching [ground]?> change y by [1] end if <touching [ground]?> change y by [1] end if <touching [ground]?> change y by [1] end if <touching [ground]?> change y by [1] end if <touching [ground]?> change y by [1] end if <touching [ground]?> change y by [1] end if <touching [ground]?> change y by [1] end if <touching [ground]?> change y by [1] end end
Offline
xlk wrote:
You could make it so as soon as the sprite touches ground, make a bunch of "if" s that move it up one pixel:
forever if <touching [ground v]?> change y by [1] end if <touching [ground v]?> change y by [1] end if <touching [ground v]?> change y by [1] end if <touching [ground v]?> change y by [1] end if <touching [ground v]?> change y by [1] end if <touching [ground v]?> change y by [1] end if <touching [ground v]?> change y by [1] end if <touching [ground v]?> change y by [1] end end
Fixed, you just needed some "v"s after the "grounds".
Regards,
CAA14
Offline
My only comment is that you shouldn't need more than one if statement if it's in a forever loop...
Regards,
CAA14
Offline
but his problem is the sprite appearing in the ground, having many of them will make it move out of the ground, if it can in 8 one pixel moves, instantaneously, so the player won't see the sprite sink temporarily in the ground.
BTW, remember to have as many of those as the fastest downwards speed (EG, if the max. falling speed is -9, have 9 of them, as it can end up up to 9 pixels into the ground). And, make sure it doesn’t happen when hitting a ceiling(!).
Offline