- Home /
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 http://www.youtube.com/watch?v=Fu8A8i8x26k at 11:49 to 11:52.
Do you have a video link as an example for people who don't know or havn't played Amnesia?
Just look up "Amnesia : the Dark Decent" on youtube and you should see it on just about the first one you look at.
If you are asking for help, do you think it is fair to make me search to help you? And how do you know what I am watching is the movement you are after?
For example, note how the OP of this question gave all the information needed to help : http://answers.unity3d.com/questions/374134/quake-like-movement.html
I apologise, I meant no disrespect. You can see the action here http://www.youtube.com/watch?v=Fu8A8i8x26k at 11:49 to 11:52.
Thanks, a picture (or video) is a thousand words. Here is a question on leaning that may help : http://forum.unity3d.com/threads/162847-Camera-rotation-quot-lean-quot
Answer by AlucardJay · Jan 06, 2013 at 09:55 AM
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.
Great thanks, but how do I make it so the player doesn't move left or right unless they press a or d?
I don't understand the question. With this script, the player doesn't move when leaning, just rotates on the Z_axis. Watch what the controller does when you press q/e. I noticed the collider stays upright, so there may even be a chance that the player won't get hit by collisions if looking around the corner.
Answer by fajarazizlaksono · Jan 06, 2013 at 01:50 PM
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,
Answer by MarkFinn · Jan 04, 2013 at 02:32 PM
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);}
}
}
}
The player character you want the camera o look at, or just replace it entirely with a point in the middle of the room/scene if you are working with a game where the camera doesn't usually move.
What I want to be able to do is rotate the camera to the side slightly so the player is able to look around any corner at any time. Say if you were trying to touch your ear to your shoulder. This is what I am trying to achieve.
Answer by D12Duke1 · Aug 02, 2016 at 12:00 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613090354im_/https://answers.unity.com/themes/thub/images/avi.jpg)