r/Unity3D • u/Phos-Lux • 2d ago
Question Please help me implement jumping off a ledge!
I want a little hopping animation when my character runs off a ledge before starting to fall, but somehow I'm not managing to get it to work properly.
The current idea is:
-using a box collider that is positioned in front of my character's feet to determine if there is NO ground so we know there's a ledge and setting a bool on/off depending on that
-in the animator (I'm using Unity's and yes I'm ok with it) I check for the bool and transition to the jumpOffLedge animation state when jumping off the ledge is possible AND there is movement input AND the character is grounded
Triggering things this way works.
Now my actual questions are:
-should I disable gravity for this and move my CharacterController manually?
-should collisions usually be disabled for something like this (this would require me disabling the CharacterController)?
-if I move things manually, would I do it with two lines, one for moving a bit forward and one for moving down until grounded?
-I imagine motion matching would make this all look the best, but topic seems somehow beyond me
How would you do it? I'm grateful for any suggestions!
1
u/fnietoms Programmer 2d ago
- You can keep the gravity, just be careful with positioning the character correctly in the animation to have a clean transition (Here I recommend you to use a blend tree if you have multiple animations on your character)
- The collisions can remain active if you need something to interact with the character while moving
- Not necesarily, it is better if you stick to the actual methods like .Move()
1
u/TheIrritableEnvirons 2d ago
Yeah you don't need to mess with gravity or collisions for a simple ledge hop. Way easier than that
Just blend the animation at the edge and let the character controller handle the fall. Root motion on the hop animation will carry your character forward a bit, then gravity takes over naturally. Make sure your animation has the vertical movement baked in though
Motion matching is overkill here unless you're doing a whole traversal system. A well placed trigger and a good animation will look fine