- Home /
climb a ladder. How to do?
i like to climb a ladder with my character. What is wrong with my code?
function climb (){
if(Input.GetButton("k")){
transform.position += Vector3(0,0,80);
}
}
Answer by TheBombix · Apr 30, 2012 at 04:33 PM
Maybe the right code is this
function climb ()
{
if(Input.GetButton("k"))
{
transform.position += Vector3(0,80,0);
}
}
Answer by TheBombix · Apr 30, 2012 at 04:41 PM
you must write your code like this one
function Update ()
{
if(Input.GetButton("climb"))
{
Climb();
}
}
function Climb ()
{
transform.position += Vector3(0,0,80);
}
then go into Unity, click on Edit - Project Settings - Input, then in Size add one button (Ex: if in Size there is 15, you must put 16) and then at the end of the list click on the last button, in "name" put climb and in "Positive Button" put k, then try if the code is valid.
Why two answers? Did you have trouble to find the edit button? ;)
Answer by svl · Apr 30, 2012 at 08:05 PM
Thanks It's good but the same. I want to climb en not jump above.
Stijn
Answer by TheBombix · Apr 30, 2012 at 08:21 PM
wait few minutes and i try to make a script on my project
Answer by Seth-Bergman · Apr 30, 2012 at 08:13 PM
re : function Update () { if(Input.GetButton("k")){ transform.position += Vector3(0,0.5,0); } } i am climing but it looks more jumping very high. How can i make a smooth climb on my ladder
...
instead of accessing position directly, use transform.Translate(Vector3(0,0.5,0) * Time.deltaTime);
Your answer
![](https://koobas.hobune.stream/wayback/20220613070925im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is this how a ladder collider works? 1 Answer
How to climb up a ladder!! 1 Answer
How to make a ladder script for unitiy's FPS controller? 1 Answer
3rd Person Ladder/Wall Climb Script 1 Answer