- Home /
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?
Answer by wccrawford · Oct 28, 2011 at 12:34 PM
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.
that's a good idea, I'll try that...and see if it works. Thanks a ton for the idea!
One thing I just thought of... You'll have to be careful of platforms you're passing over, but won't actually land on... So I'd check that you're actually going to land on the platform before starting the animation.
Oh, and going up, as well. I'd only start the animation if you're headed down.
tru dat! Yeah, that's the really tricky part--is figuring out which one you're going to land on. I guess you could just assume that you're going to land on the first thing you pass over, else{the bottom of the level}. There aren't that many platforms in the game that it would be an issue, I think. Good points, guys.
Answer by syclamoth · Oct 28, 2011 at 12:36 PM
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.
Thanks, syclamoth! I think that will probably work better. And by "work better" i mean "I understand your explanation a bit more." Cheers, though.
Your answer
Follow this Question
Related Questions
Detecting the right time to play a landing animation? 1 Answer
Detaching a Physics Driven Object from a Character 2 Answers
the animation walk but he still in the same place and rotate left and right on this white circle 0 Answers
Enemy AI Animation 0 Answers
Matching character's rotation to the rotation of a animation - How? 0 Answers