Issues with making a climbing script compatible with CharacterController
Heya!
I'm working on my first script without following a tutorial, but I've hit a bit of a problem. What I'm trying to accomplish is a climbing script, so when the player is in the trigger, they press R to climb up, and F to climb down.
Now my problem is, I'm using a CharacterController and my script is set up with a trigger. I don't know all the terminology or commands for C# in Unity, despite going through the manual. Right now this is the script that I am using:
public class ClimbLadder : MonoBehaviour
{
public GameObject Climbable;
public CharacterController CharacterController;
public GameObject Player;
public float climbSpeed = 15f;
public float gravity = 0f;
private Vector3 moveDirection = Vector3.up;
void OnTriggerEnter (Collider Climbable)
{
if (Climbable.CompareTag("Player"))
{
Debug.Log("Player has entered climbing trigger.");
}
}
void OnTriggerStay(Collider Climbable)
{
if(Climbable.tag == "Player")
{
if(Input.GetKeyDown(KeyCode.R))
{
transform.Translate(Vector3.up * Time.deltaTime);
}
if (Input.GetKeyDown(KeyCode.F))
{
transform.Translate(Vector3.down * Time.deltaTime);
}
}
}
void OnTriggerExit(Collider Climbable)
{
if (Climbable.CompareTag("Player"))
{
Debug.Log("Player has left climbing trigger.");
}
}
}
I've made a Debug.Log to tell me whenever the player is inside the trigger, so it's not a case of not actually being inside the trigger. My player has a Player tag too. I think I'm just not using the right terms or commands, since this is being used with the CharacterController.
I also read in another post that someone tried disabling the CharacterController while in the trigger, but the problem with that is, once it's disabled, you can't move out of the space to enable it again.
I've also got everything set up in the inspector as well, so I'm certain it's just a matter of not using the right command words/termonology that works with CharacterController.
Your answer
Follow this Question
Related Questions
Player still move left&right in MenuUI 0 Answers
Character swap breaks movement. 1 Answer
Character flies up and gets stuck there, won't move forward? 1 Answer
Grappling hook physics script error 0 Answers
IsGrounded flickers when hitting a wall 0 Answers