I’ve been working on a first person game in the vein of a Looking Glass game, and one of the major aspects of those games is their really natural feeling lean, specifically in the first Thief.
My setup for the player controller is pretty typical,
- Character Controller
- A game object in very center of that
- A camera up from the center
Then this code is on the Character Controller
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()
{
if (Input.GetKey(KeyCode.Q))
curAngle = Mathf.MoveTowardsAngle(curAngle, maxAngle, speed * Time.deltaTime);
else if (Input.GetKey(KeyCode.E))
curAngle = Mathf.MoveTowardsAngle(curAngle, -maxAngle, speed * Time.deltaTime);
else
curAngle = Mathf.MoveTowardsAngle(curAngle, 0f, speed * Time.deltaTime);
My problem is that every time I lean the character near a wall the camera clips right through. In Thief what happens is the camera bumps against as if it were a physical object, and so I tried adding a collider to the camera and it didn’t do anything.
How can I make it so that the wall stops the camera?