Character Leaning
Creating a player peaking function, I'm trying to replicate Alien Isolation peaking system. I feel like I may need to restart the entire script, I may be doing this the harder way. But anyway, I made a RigidBody on my camera in order to have camera physics, layered it in between invisible boxes that don't collide with the player or obstacles so that the camera's movement is limited.
Creating a boolean statement, when the player presses LeftCtrl movement is disabled and then leaning is enabled. By pressing WASD the Rigidbody will move the camera on the X and Y axis, when LeftCtrl & WASD are not press leaning is disabled, the rigidbody camera moves back to it's default position (an empty game object) and movement is enabled, however that's the problem.
Issue: The Rigidbody camera won't go back to it's default position (an empty game object) unless LeftCtrl & WASD are not being press.
Video: https://www.youtube.com/watch?v=RqMzp8RgZ5s
My Code:
private void playerLeaning()
{
if (Input.GetKey(KeyCode.LeftControl))
{
canLean = true;
canMove = false;
cameraBody.Sleep();
//NOTE: Ctrl + A or D move Camera Body to left or right
leanHorizontal = Input.GetAxis("Horizontal");
//NOTE: Ctrl + W or S move Camera Body to Up or Down
leanVertical = Input.GetAxis("Vertical");
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S))
{
playerLeaningInput = (transform.up * leanVertical + transform.right * leanHorizontal);
cameraBody.AddForce(playerLeaningInput.normalized * leanForce, ForceMode.VelocityChange);
}
}
else
{
canLean = false;
}
if (canLean == false)
{
//NOTE: I want this to be called first before canMove == true
cameraBody.position = Vector3.Lerp(transform.position, PlayerToCamera.position, lerpTime);
cameraBody.rotation = Quaternion.Lerp(transform.rotation, PlayerToCamera.rotation, lerpTime);
canMove = true;
}
}