- Home /
Ledge Hang script
I have a character named (in editor) character284 I would like it to automatically grab on to a ledge when within a raycast. I would like to have variable that give raycast size. When it touces the ledge, have the code play anim (ledgehang). It would be nice to have it grab on and stay on, but still be able to jump off. Thanks in advance.
That was very helpful, but I'm still mainly an artist. I would like to hae a script, but I don't know if you need more info. Thank ou very much, but I would greatly like a script.
you should use comments ins$$anonymous$$d of making a new answer for replying to someone else's answer
Also; this isn't a place for asking for someone to do work for you. For that there is this; http://forum.unity3d.com/forums/31-Commercial-Work/page2?order=desc
This Q&A is for developers to share insight and ask questions mainly focused towards issues with building apps in Unity.
Scripts and code arnt one-size-fits all, only the most basic of code can be "plug and play" everything else will need some sort of customizations to fit your particular scenario.
Answer by jbishop 1 · Jan 02, 2010 at 12:52 PM
What is your question, exactly? How to implement this? How to trigger animations from a collision callback?
Animations and collisions are well covered in the docs, so here is a general overview of how to attack the desired functionality. Back in the day, I did this for a Zelda:OOT type control; not a trivial task!
You will first need to detect the wall (a sphere collision might be more efficient than your cast), then you need to briefly disable input and orient your player-character to face the the wall at a pre-defined distance (whatever works for your animation).
Then, play your animation and put the player-character in the appropriate state to handle new input (e.g. up to continue climb, or down to drop off of wall). Note that your 'climb' animation should end where your 'hang' animation begins and that you will have to keep your walls vertical, your floors flat and your ledges perpendicular where you climb or your animations are going to cut through the level geometry.
If you have different heights or types of walls, you can attach or embed (i.e. name) information to the wall, or you can provide the player-character with a set of raycast "sensors" (top, bottom, left, right, whatever you need) to determine the appropriate action to take.
For instance in your grab ledge, but still be able to jump off example, you would need sensors pointing down to detect a ledge and sensors pointing forward to detect a wall. You would have to model the ledge in your collision geometry (which should be SEPARATE from your visual geometry) as a strip of floor just at the top of jumpable walls.
Building 'smart' collision geometry like this can be very time consuming and requires a lot of discipline to keep clean and synchronized with the level graphics. Just making sure there are no open seams or holes can be a nightmare.
I think you might be opening pandoras box here :) But dive in, that is the best way to learn.