D
Dibidoolandas
Guest
I'm struggling a bit to come up with a good solution for how to push my player out of the way of a falling block so that they don't get stuck in a wall when it lands on them.
I originally just had code to kill the player in place if this happened, but if I could enable some kind of push to the side I think it would be a better experience. I've attached an illustration of the problem.
Currently I've added some code to say that if the block falls on the player's head, then it checks if the player's x is to the right or left of the block's x, and whichever side he's closest to, push his x value out of the block. This works, however as you'll see in the illustration, if my player was butted up against a wall and this code ran, it would push him straight into the wall and he'd be immobilized. So in theory I'd like it to know which side of the block will have clear space when it lands, and push the player in that direction. If there's no clear space (such as in a pit the same size as the block), then I would just kill the player.
Has anyone dealt with this before? I've looked around a little and not seen much... If there are any resources for dealing with this I'd appreciate it.
I originally just had code to kill the player in place if this happened, but if I could enable some kind of push to the side I think it would be a better experience. I've attached an illustration of the problem.
Currently I've added some code to say that if the block falls on the player's head, then it checks if the player's x is to the right or left of the block's x, and whichever side he's closest to, push his x value out of the block. This works, however as you'll see in the illustration, if my player was butted up against a wall and this code ran, it would push him straight into the wall and he'd be immobilized. So in theory I'd like it to know which side of the block will have clear space when it lands, and push the player in that direction. If there's no clear space (such as in a pit the same size as the block), then I would just kill the player.
Has anyone dealt with this before? I've looked around a little and not seen much... If there are any resources for dealing with this I'd appreciate it.