playMaker

Author Topic: Triggering Falling animation  (Read 2538 times)

unearthly

  • Junior Playmaker
  • **
  • Posts: 62
Triggering Falling animation
« on: November 09, 2021, 04:02:41 PM »
Hi, I have a 3D character with which I want to go into a fall animation when going down a steep slope or off a cliff. But if the distance is no more than two meters the character should change back to a walking animation.

I understand I need to detect whether the character is grounded and use some kind of bool to trigger the animations.

paradiseprime

  • Full Member
  • ***
  • Posts: 106
Re: Triggering Falling animation
« Reply #1 on: November 09, 2021, 11:30:17 PM »
I am assuming you are using a rigid body.

1. Get Velocity + Float Compare
2. If velocity is negative then target is falling

Now you will have to tweak it to fit your situation as sometimes you dont want to go into fall every time you go into the negatives.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Triggering Falling animation
« Reply #2 on: November 10, 2021, 10:57:31 AM »
Hi.
Probably a good way is to use 1/2/3 raycasts (left / right / center, only center can work but you might want to do 2/3 the have more accuracy) of the character, set the distance to the maximum and you can use a bool test (or Fsm Bool test from another fsm)
Also you can use the distance, but probably you can to check if it hit or not before that.

unearthly

  • Junior Playmaker
  • **
  • Posts: 62
Re: Triggering Falling animation
« Reply #3 on: November 11, 2021, 02:26:20 AM »
Thanks for your reply, I am using a character controller. I know how to attach raycasts, but not how to trigger a falling animation from them, let alone a landing one. I really need a tutorial with a set by step explanation.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Triggering Falling animation
« Reply #4 on: November 11, 2021, 07:31:29 AM »
Hi.
For the animation, you can add a bool parameter (name it Grounded for example) and use Set Animator Bool.

then on the animator transitions you can set a condition if the bool is true or false to change animations.

For animator you should find several tutorials on youtube, search for 'unity animator tutorial'

unearthly

  • Junior Playmaker
  • **
  • Posts: 62
Re: Triggering Falling animation
« Reply #5 on: November 14, 2021, 12:50:15 AM »
Hi,

this is what I have tried, but it goes to the fall animation whatever I change. Is any of this usable?

Thanks in anticipation.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Triggering Falling animation
« Reply #6 on: November 16, 2021, 08:38:18 PM »
Hi.
on the Grounded? fsm where you do the spherecast, add the action 'Set animator Bool'
and place the IsGrounded variable on the Value From the 'Set animator Bool' Action.
also have every frame enabled

you can remove the other fsms.

unearthly

  • Junior Playmaker
  • **
  • Posts: 62
Re: Triggering Falling animation
« Reply #7 on: November 18, 2021, 12:33:13 AM »
Hi djaydino,

I have done as you suggest, now the 'grounded' Animator bool is on true, always.

I can see that the Spherecast is correcty seeing the objects beneath the player character, but the falling animation does not play when there are no objects beneath.

Groo Gadgets

  • Beta Group
  • Full Member
  • *
  • Posts: 175
Re: Triggering Falling animation
« Reply #8 on: November 18, 2021, 03:23:25 AM »
I can see the problem in your screenshot. You haven't applied the IsGrounded bool value to the Set Animator Bool action properly.

unearthly

  • Junior Playmaker
  • **
  • Posts: 62
Re: Triggering Falling animation
« Reply #9 on: November 18, 2021, 06:49:31 AM »
Thanks Groo Gadgets.

I used the IsGrounded value and it now works. :)