How to get actor to die when squished
I am making a platformer game where the player can ride a moving platform, which travels horizontally, between two still platforms. I want the player to die if he gets crushed in between the moving platform and the still platform, instead of just glitching through the moving platform. I have tried many different ways but can never get the player to consistently die when crushed.
Best Answers
-
CORE Game Posts: 280
There are many way to do it, I can give you one which might not be the best practice but, you can constrain the player X and Y to public attributes PlayerX and PlayerY , then create 2 invisible actors and let them follow the player (one a bit behind the player another in front of the player (call them Front / Back collider) and make it shorter a bit than the player so it won't touch while walking with the platform.
if the collider (back or front) touches the platform then he is between the platforms.
I will think of another way too and will let you know
Answers
You could have a rule something like:
When the two platforms are colliding and the player.Y is below where it should be (i.e. below the platform.Y+(platform.height/2)
->Then here you can do whatever you want to the game...
Something like this. Hopefully this helps.
triangularitygames.com
I already tried that, it makes they player die whenever they is touching the side of thr platform even if he is not getting squished.
I tried doing this with a platform width too, but it didnt work because the platform width/2 only updates when the player is touching the moving platform so if the player touches it, waits until it moves a bit and then touches it again, they will die before the platform width/2 updates,