Character controls seen in Amnesia

Hi everyone. How would I make my fps camera rotate slightly to the right or left like it does in Amnesia when you press “q” or “e” for looking round corners? Think of it as touching your ear to your shoulder if you haven’t played Amnesia before. I am fairly new to scripting so I need some help. All input is appreciated, thanks.

Edit : You can see the action here Scary Games - Amnesia Lost The Lights Walkthrough Part 5 w/ Reactions & Facecam - YouTube at 11:49 to 11:52.

Sorry if the comments seemed harsh, after posting many mod comments, it is just easier to get help if all the information is supplied up front. I did find this interesting, and after searching for look around corner and lean, there really is no immediate answer out there. So I have had a go at writing something to answer your question.

Disclaimer : I have a very hard time with rotations !

this mostly works. There is a jump if you lean left then lean right straight away, and if you rotate the camera then it breaks (may do odd things), but this is the best I could come up with for my skill level :

#pragma strict

var leanAngle : float = 35.0;
var leanSpeed : float = 5.0;
var leanBackSpeed : float = 6.0;

function Update () 
{
	if (Input.GetKey("q")) {
	   LeanLeft();
	}
	
	else if (Input.GetKey("e")) {
	   LeanRight();
	}
	
	else
	{
		LeanBack();
	}
}

function LeanLeft() 
{
	// current Z-rotation
	var currAngle : float = transform.rotation.eulerAngles.z;
	//var rot : Quaternion = transform.rotation;
	
	// target Z-rotation
	var targetAngle : float = leanAngle;
	
	if ( currAngle > 180.0 )
	{
		//targetAngle = 0.0 - leanAngle;
		currAngle = 360 - currAngle;
	}
	
	//lerp value from current to target
	var angle : float = Mathf.Lerp( currAngle, targetAngle, leanSpeed * Time.deltaTime );
	
	//Debug.Log ( "Left : currAngle " + currAngle + " : targetAngle " + targetAngle + " : angle " + angle );
	
	// rotate char
	var rotAngle : Quaternion = Quaternion.Euler( transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, angle );
	transform.rotation = rotAngle;
}

function LeanRight() 
{
	// current Z-rotation
	var currAngle : float = transform.rotation.eulerAngles.z;
	
	// target Z-rotation
	var targetAngle : float = leanAngle - 360.0;
	
	if ( currAngle > 180.0 )
	{
		targetAngle = 360.0 - leanAngle;
	}
	
	//lerp value from current to target
	var angle : float = Mathf.Lerp( currAngle, targetAngle, leanSpeed * Time.deltaTime );
	
	//Debug.Log ( "Right : currAngle " + currAngle + " : targetAngle " + targetAngle + " : angle " + angle );
	
	// rotate char
	var rotAngle : Quaternion = Quaternion.Euler( transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, angle );
	transform.rotation = rotAngle;
	
}

function LeanBack() 
{
	// current Z-rotation
	var currAngle : float = transform.rotation.eulerAngles.z;
	
	// target Z-rotation
	var targetAngle : float = 0.0;
	
	if ( currAngle > 180.0 )
	{
		targetAngle = 360.0;
	}
	
	//lerp value from current to target
	var angle : float = Mathf.Lerp( currAngle, targetAngle, leanBackSpeed * Time.deltaTime );
	
	//Debug.Log ( "Center : currAngle " + currAngle + " : targetAngle " + targetAngle + " : angle " + angle );
	
	var rotAngle : Quaternion = Quaternion.Euler( transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, angle );
	transform.rotation = rotAngle;
}

The link I provided was the best I could find, but the code in there doesn’t work I found out! The rotations always left the character facing forward.

This will depend somewhat on how you control your camera now.

Assuming that you use “transform.LookAt(playerCharacter.transform)” or similar you could simply add an offset to the lookAt target.

Very crude example follows.

using UnityEngine;
using System.Collections;

public class lookatit : MonoBehaviour {
	
	public GameObject target;
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if (target!=null)
		{
			if (Input.GetKey(KeyCode.Q)){transform.LookAt(target.transform.position+new Vector3(3, 0, 0));}
			else if (Input.GetKey(KeyCode.E)){transform.LookAt(target.transform.position+new Vector3(-3, 0, 0));}
			else{transform.LookAt(target.transform.position);}
		}
	}
}

A bit old on the answer, but lerping the camera is a horrible way of trying to ‘lean’ the camera… It’s unreliable for precision.

What I did, goofing around just now taking a break from my neverending bloody project…

I created a ‘lean left’ and ‘lean right’ camera and I parented them to my main camera at 0 0 0, from there when I did a simple do-tween to -.04 -.002, -.008 for left and copy pasted it for right removing the negative values… On ‘Q’ press down or ‘E’ press down, it will switch to that camera, play the lean animation (woot for mixamo!) on the character and commit to the dotween. It was figity as hell so i through a rigidbody on it and gave it .2 drag and froze position. The end result was very close to Rainbow Six Ravenshield peaking. i 'spose i could upload a video of how I did it… I used playmaker.

wow yamimash …
i like him XD , come to the mash ,
everytime i open youtube just to see him…

sorry I did not answer your question, the answer is readily available above,