playMaker

Author Topic: Player Is Falling  (Read 2839 times)

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Player Is Falling
« on: October 23, 2015, 11:59:25 AM »
Hi!

I have asked about this before, but I ask again! And I hope I will solve it this time with some help!

This is a 2D platformer. My problem is when the player is falling down from a platform edge. I want the player to change to falling animation. I tried with a trigger on the player. And tag the platforms ground or something. The problem here, is when the player falls down from the platform and hit the side of the platform which has the tag ground, it will check the player as grounded.

I think the best way is to use Raycast, so I created two empty game objects for the Raycast. One for left side and one for right side. But it's problems here also.

One of the things I've tried, is to have two FSM for the Raycast. Left side and right side. And then I disable the left Raycast FSM when I'm walking to the right. And the same the other way. The problem is when the player is close to the edge and I turn the player, then I enable the disabled FSM and the player will be checked as falling.
So this was not good. I've also tried to have two Raycast for left and right side on the same FSM. It didn't work so good either.

Can someone help me to find the best solution?

Thanks! :)
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

ManicMinerUK

  • Junior Playmaker
  • **
  • Posts: 51
Re: Player Is Falling
« Reply #1 on: October 23, 2015, 10:01:33 PM »
Wouldn't the best way be to try and detect downwards motion rather than using collision checks?

I would create an FSM that got the player position, waited a short period of time (1 frame = 0.02 seconds, usually) and then compared the current player position to that saved position - if the Y axis (or whichever axis is down in your game) has gotten smaller, then trigger the falling anim?

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Player Is Falling
« Reply #2 on: October 24, 2015, 09:29:05 AM »
Hi!

So, I create a new FSM? Add Get Position and store it in variable? Should I check every frame? And this is the current position, right? What is the save position, so I can compare these two?
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Player Is Falling
« Reply #3 on: October 24, 2015, 11:35:02 AM »
This is what I did and it works!

On the first state, I have two get position the first get position, I store it in variable I called current position where I also check every frame. The next get position, I store it in variable called saved position. Then I compare these two variables. If the current position is less than saved position, then the animation fall is playing. Next state I use a raycast to check if the player is grounded. It works. Maybe it wasn't exactly what you had in mind. :)
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

ManicMinerUK

  • Junior Playmaker
  • **
  • Posts: 51
Re: Player Is Falling
« Reply #4 on: October 24, 2015, 11:46:07 PM »
if it works, it works :)

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Player Is Falling
« Reply #5 on: October 25, 2015, 12:23:05 PM »
But thanks for giving me the idea of using get position. :) Never thought about that before!
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no