I’m making a 2D fighter in a combined style of Street Fighter and Super Smash Bros. I have been searching and searching for the answer… can’t find it. Not even one tutorial gives me the proper answer. I’m thinking that when I’m within the vicinity of a ledge, I snap to the proper position and hang. Inputting “Up” would make me climb which “Down” would make me fall. How would I go about this, and as a bonus would I be able to change the hit-box per frame?
Based on my limited experience, I would guess that you would use a raycast to look for a valid platform in front of the player character and a lack of a platform above and in front of the player character when jumping. If the raycast directly in front of the player detects a platform and the raycast in front of and above the player doesn’t, it means that the player is at the edge of a platform.
The rest could be done however you’d prefer to handle stopping in place and waiting for further player input.
That’s my two cents, anyway.
I know how to detect ledges… not how to climb them or simply hang.
That depends a lot on how you implemented movement. I mean, if the hanging ledge is detected and you want the player to automatically hang there when the opportunity arises, you could set a boolean for hanging that will prevent horizontal movement. While that boolean is set, keep the player’s vertical velocity set at 0 each frame and set the animation state machine to the hanging frame.
If the player hits down, cancel out of the hang so the player can drop as normal. If they hit up, play the climbing animation. There may be some fiddling necessary to make the animation + player movement up onto the platform look convincing, though.
Or that may be no help at all, depending on how your jumping and such are set up.
Actually, my jumping is set up with velocity and jumping force. This should work purrfectly. Thanks!
One question, though: how would I disable movement?
Whoops, didn’t see how old the post was. My apologies!
Disable the rigidbody to stop physics from acting, Have a lock bool in the script to prevent unintended movement or just divert input to a different set of actions while in “ledge mode.”
You could switch the Gravity off using useGravity when player enters a trigger at top of ledge then back on when exits trigger also could turn rigidbody velocity to 0,0,0 to make them stop moving, just an alternative idea ![]()
If(Input.GetAxis(“horizontal”) && onledge == false)
{ do movement stuff}
That would stop horizontal movement if onledge boolean was true… Same for vertical if change input aiii
It depends how do you program your character. Search about states machines and you will see that is the better way to make things like that.
i have recently been looking into state machines and yes is far better =)