- Home /
Lean/Peak system
Hey people, so im trying to do a lean/peak system like the one we see in Rainbow Six Siege, i have an idea on how to do this but i am unable to execute it… I have a script for my character, and one for my character camera, Here is how much camera is looking…
// Update is called once per frame
void Update()
{
CameraRotation();
if (Input.GetKey(KeyCode.Q))
{
isLeaningLeft = true;
transform.Rotate(0, 0, -10 * Time.deltaTime);
}
else
{
isLeaningLeft = false;
}
if (Input.GetKey(KeyCode.E))
{
isLeaningRight = true;
print("Leaning Right");
}
else
{
isLeaningRight = false;
}
}
I also store the initial position of the camera so that i can later return to it
Transform playerCamera;
Vector3 initPos;
Quaternion initRot;
bool isLeaningLeft;
bool isLeaningRight;
// Start is called before the first frame update
void Start()
{
//This doesn't matter here..
//LockCursor();
//xAxisClamp = 0;
initPos = playerCamera.localPosition;
initRot = playerCamera.localRotation;
}
So this obviously doesn't work, and i understandw why it doesnt. Do i need to use quaternion or euer angles? If anyone could point me in the right direction it would be really appreciated, thanks.
Answer by toficofi · May 20, 2019 at 09:52 PM
You could make new points in the GameObject that represent where the camera should be when the player is leaning, and give them some rotation too. Then you can use https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html and https://docs.unity3d.com/ScriptReference/Quaternion.Lerp.html to smoothly move from the "center" position to a "leaned" position.