How to add Ladder Movement / Feature to 3D First Person Controller

Hello everyone, I’m trying to add ladders to my first person shooter, shouldn’t be that complicated and I think I’m almost there too but I just can’t figured out what I’m missing. When I try to move the ladder up my Character keep falling down. This is a part of my FirstPerson Movement Script:

void Update(){

isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}

x = Input.GetAxis(“Horizontal”);
z = Input.GetAxis(“Vertical”);

move = transform.right * x + transform.forward * z;

//--------------------------------------Ladder attempt----------------------------------------------
if(Physics.Raycast(transform.position + Vector3.up * .8f, transform.TransformDirection(Vector3.forward), out RaycastHit raycastHit, 1.2f)){
if(raycastHit.transform.tag == “ladder”){
move.x = 0;
move.y = move.z * -1f;
move.z = 0;
isGrounded = true;
}
}
//--------------------------------------Ladder attempt end----------------------------------------------

controller.Move(move * speed * Time.deltaTime);

if (Input.GetButtonDown(“Jump”) && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2 * gravity);
}

velocity.y += gravity * Time.deltaTime;

controller.Move(velocity * Time.deltaTime);
}
}
}

If some could fix this quickly I would be so greatful!

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

That’s not really how any kind of software engineering works anywhere in the world.

Instead, it’s time for you to start debugging.

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

When you learn more, if things are still mysterious:

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

Sorry, that was my first time writing in a forum. I created a new thread.

PS: I tried debugging and a lot of other things the last couple of days, writing in a forum is always the last thing I consider…