lock my FPS camera or direct it to face z
what I am doing is making it so when the player stands in front of a ladder he climbs it when you hit the E key. He is actually standing on a platform that slowly animates upwards. Basically it looks like he is riding an elevator instead of climbing a ladder. I want the camera to face the ladder ( which is looking straight ahead up the z axis - the y rotation is zero). I have tried various LookAt scripts and quaternion rotation and even just "simply" setting the transform rotation to zero ( but Unity won't let me). So the question is...how do I get the camera to face the ladder. Currently I have it so the horizontal Sensitivity of my mouse goes to Zero so I can make it so I can't rotate, but I want to call that function only after I have turned to face the ladder. Here is the script I have so far. Obviously the sensitivity change will need to happen AFTER I face the correct direction. The ladder is in a little alcove so the player is kind of forced to face it, but there is the possibility of him turning to one side or the other before hitting the E key
using UnityEngine;
using System.Collections;
public class climbLadder : MonoBehaviour {
Animator anim;
public Transform that;
void Start () {
anim = GetComponent<Animator>();
}
void OnTriggerEnter(Collider other)
{
if(other.tag == "Player")
{
if (Input.GetKeyDown(KeyCode.E))
{
anim.SetTrigger ("Climb");
FPSCamera.horizontalSensitivity2 = 0;
//FPSCamera.viewTarget2 = that;
}
}
}
void OnTriggerExit(Collider other)
{
if(other.tag == "Player")
{
anim.ResetTrigger ("Climb");
anim.SetTrigger ("leave");
FPSCamera.horizontalSensitivity2 = 250;
}
}
}
Your answer
Follow this Question
Related Questions
How to rotate the object when you move to always look at the same point 1 Answer
How to face towards vertical collider? 0 Answers
How to turn a character? 1 Answer
Make an object follow and face an object while maintaining distance from a different object. 0 Answers
Making a fixed camera system and having trouble with gimbal lock 0 Answers