Detecting the right time to play a landing animation?

Hey, so, here’s an interesting problem. I’ve got a 2D sprite, in a platforming game (I’m using SpriteManager 2). The main character relies on a rigidbody to handle physics. I have a sprite animation sequence that I want to play whenever I get a certain distance from the ground, or whenever the player approaches the ground. I can change the framerate that the landing animation plays, to accomodate landing from various heights. But I haven’t yet figured out a solution that solves all three of these problems:

  1. The character can land on a platform by jumping up to it, meaning he will not land at the same height he started at.

  2. The character can land on something by falling down to it from a higher platform, meaning, again, that he doesn’t end up at the same height.

  3. The character can jump at a range of heights–so putting a cube below him that detects when it hits the ground (and thus triggers the animation) doesn’t really work correctly.

The way I’m currently attacking the problem is via the method mentioned in problem 3. Any idea of a better solution?

I would determine how fast you are falling, and raycast down. Using a calculation from the raycast distance and your current speed, figure out if the platform is close enough to start the animation.

This calculation is going to be dependent on how much time you need, etc.

You could raycast towards the ground, using the rigidbody’s velocity multiplied by the number of seconds ahead that you want to predict. Of course, this won’t account for gravity- however, if you look up some physics equations, there are ways of getting around that (assuming a constant acceleration etc.). Then, if this raycast hits the ground (use a layermask or something), play your land-anticipation animation.