Hello! I’m working on a third person game where my character detects a tag using a Raycast and then climbs to the top of that object, but I’m pretty much stumped when it comes to the code of going up there. Do anyone have any advice as to how I can make my character climb up different heights?
Control.cs
RaycastHit hit;
if(Physics.Raycast(transform.position, transform.forward, out hit, 4f)){
if(hit.collider.tag == "Vault" && Input.GetButtonDown("Jump"))
// Do climbing code here?
}
This isn’t something that’s just going to be solved in a random forum post, especially if you’re looking for Assassin’s Creed level of smooth climbing – you do mean climbing, not vaulting which is jumping over something right? – but you can use Collider.bounds to find the top of the object you’re scaling, then project your character up and towards that point.
One approach that generally works well in Unity is to have different controllers for different movements.
For instance you have the third person controller for walking around, but when you reach a ladder or wall, you would enable the climbing controller, disabling the third person controller.
The easiest way to handle this to have a master controller that is aware of which of the other controllers should be active. Another example would be a swimming controller for when the player hits water.