- Home /
Question by
unity_QOya9nD58KG7cg · Aug 14, 2020 at 10:46 AM ·
cameracamera rotatecamera movementfps controllerlean
FPS Leaning movement!
I have a lean script for my FPS controller but im not happy with how it works! When i use it to peak around corners it dosent have any effect it just rotates the camera! How would i go about adding a tiny movement whenever i lean for example if i lean right it moves a tiny bit to the right and same for left so that it actually works to peak around corners?
public class LeanBehaviour : MonoBehaviour {
public Transform _Pivot;
public float speed = 100f;
public float maxAngle = 20f;
float curAngle = 0f;
// Use this for initialization
void Awake()
{
if (_Pivot == null && transform.parent != null) _Pivot = transform.parent;
}
// Update is called once per frame
void Update()
{
// lean left
if (Input.GetKey(KeyCode.Q))
{
curAngle = Mathf.MoveTowardsAngle(curAngle, maxAngle, speed * Time.deltaTime);
}
// lean right
else if (Input.GetKey(KeyCode.E))
{
curAngle = Mathf.MoveTowardsAngle(curAngle, -maxAngle, speed * Time.deltaTime);
}
// reset lean
else
{
curAngle = Mathf.MoveTowardsAngle(curAngle, 0f, speed * Time.deltaTime);
}
_Pivot.transform.localRotation = Quaternion.AngleAxis(curAngle, Vector3.forward);
}
}
Comment
Your answer
Follow this Question
Related Questions
How to rotate camera diagonally over players shoulder while still facing towards players direction 0 Answers
How to rotate camera diagonally over players shoulder while still facing towards players direction 0 Answers
Automatic Camera Rotation in the 3D Game Kit 0 Answers
Lean/Peak system 1 Answer
Camera/can't turn on X 1 Answer