Hello, I have never used unity before. But I am looking for a script that will allow a character to climb a wall like assasins creed, as in grab the nearest ledge the player is moving towards. How simple is this to do?
And is there anyone who can step me through some code and show me how to achieve this?
I’m not very sure, But I can give you some pointers that will help out.
For one, if you are new to unity, and scripting in general, I would go watch tornadotwins videos on youtube, or go to 3DBuzz.com and watch their unity training videos, they are free.
Back to the assassins creed like script.
I am guessing it would be something like this:
var distanceToEdge = vector3 distance (http://unity3d.com/support/documentation/ScriptReference/Vector3.Distance.html)
if(distanceToEdge <= 0.5)
{
grab();
}
function grab()
{
lock gravity
press KEY to turn gravity back on
}
Something along those lines, ive never done it before so I’m not comepletly sure.
http://unity3d.com/support/documentation/ScriptReference/Vector3.Distance.html
should help.
If you have some cash http://www.gameprefabs.com/products/show/87 there is also java version if that is your language of choice
I have done this, the code is fairly abstract and modular so it would be hard to mash it into a meaningful response, but here is a synopsis.
I have a controller manager, and that controller manager registers several different controllers with it (i.e. default movement, swimming, climbwall, climbrope, climbladder, etc).
Each frame (or whenever you want, i found ontrigger/oncollision unreliable for this), the controller manager polls each of it’s controllers by calling a method on them “IsAvailable”.
If the user is pressing the F/action key AND one of the controllers IsAvailable - it disables the active default controller and enables the target controller.
So then you just need to figure out how to determine if a controller is in an available state. For my wall climb, I use a script “Climbable” and so in the “ClimbWallController” for instance, my “IsAvailable” method does a raycast forward and if there is a hit on an object with a Climbable attached within a short distance, it returns true for IsAvailable, and the controller manager activates this controller if the user is pressing the action/F button.
A simpler approach might also be to use a Plane, give it a Tag (“Climbable”) and then raycast out front of the player to determine if you should activate it.
Hope that helps.
BTW, the aformentioned controller prefab was one i looked at too, but it has a bunch of issues (just try the web preview and you’ll see), which is why I wrote my own.