Hi, I have an air vent attached in to a wall, I want when I press E my character plays a climb animation and enter inside,
I have tryed with 3 cameras (a climb animation camera, a bottom view displayed when i’m inside the air vent, and the regular one it is the the default on first person controller) I’m playing the climb animation, swaping to the bottom view camera and setting the position of player were climbing camera animation finishes, this look so weird like hard trasnactions between cameras and player falling until it reach ground…
Can anyone give me a tips or hints on how to achieve this better?
Actual code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class climbing : MonoBehaviour {
private bool canClimb;
private bool waitClimb;
public Animator anim;
public Camera climbingCam;
public Camera regularCam;
public Camera ventCam;
public Text escalarVentilacion;
// Use this for initialization
void Start () {
waitClimb = true;
}
void FixedUpdate()
{
RaycastHit hit;
Ray landingRay = new Ray(transform.position, transform.forward);
if (Physics.Raycast(landingRay, out hit, 8))
{
if (hit.collider.tag == "Climb" && hit.distance < 2)
{
escalarVentilacion.text = "Pulsa 'E' para entrar en el conducto de ventilación";
canClimb = true;
}
else
{
escalarVentilacion.text = "";
canClimb = false;
}
}
}
// Update is called once per frame
void Update () {
if (canClimb && waitClimb && Input.GetKeyDown(KeyCode.E))
{
waitClimb = false;
regularCam.depth = 0;
climbingCam.depth = 1;
anim.SetBool("Climb", true);
StartCoroutine(afterClimb());
}
}
IEnumerator afterClimb ()
{
yield return new WaitForSeconds(2);
anim.SetBool("Climb", false);
transform.position = climbingCam.transform.position;
ventCam.transform.rotation = climbingCam.transform.rotation;
ventCam.transform.position = climbingCam.transform.position;
ventCam.depth = 1;
climbingCam.depth = 0;
}
//private void OnTriggerEnter(Collider other)
//{
// if (other.tag == "Climb")
// {
// canClimb = true;
// }
//}
//private void OnTriggerExit(Collider other)
//{
// canClimb = false;
//}
}
