using UnityEngine;
using System.Collections;
public class CameraCrouchOffset : MonoBehaviour {
public float StandingEyeHeight = 0.0f;
public float CrouchingEyeHeight = -0.75f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//The transform.up, below, gives the object's own "up" vector, rather than world's "y" axis. This is better practice.
Vector3 StandingEyeOffset = transform.up * StandingEyeHeight;
Vector3 CrouchingEyeOffset = transform.up * CrouchingEyeHeight;
//The value of Input.GetAxis("Crouch") is going to be between 0 and 1.
//So when it's at zero, the camera's offset will be equal to StandingEyeOffset.
//When it's 1, the offset will be the same as CroucingEyeOffset.
//If it's anywhere inbetween, it will be a blend of the two target vectors.
transform.position = Vector3.Lerp(StandingEyeOffset, CrouchingEyeOffset, Input.GetAxis("Crouch") );
}
}
asked
Aug 24 '10 at 02:07 AM
wishing
17
●
2
●
4
●
4
"translating this C# to javascript" is not a question. I assume you want a JS version of it. Make an effort. If you get hung up, ask an actual question so we can help you get through it.
We could translate it, but you'll learn so much more doing it yourself, it's worth the effort.