I have a first person controller and I’m working with a first person melee type game. When the player attacks and they are in range of an enemy The camera and player itself rotate towards the closest enemy using this script.
if (gosDistance < snapDistance)
{
snapping.SetActive(true);
var rotation = Quaternion.LookRotation(closest.transform.position - transform.position);
//Debug.Log(rotation);
player.transform.rotation.y = Quaternion.Slerp(transform.rotation.y, rotation.y, Time.deltaTime * damping);
playerCamera.transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
//playerController.transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
The real problem I am having is afterwards the axes for the player and camera get stuck in a sort of gimbal lock I think and currently the only way I have for resetting that is to to change the player and cameras rotation all back to (0,0,0)
, but that doesn’t flow well with the gameplay. Is There any way that the camera and players rotation can be reset without having to face the player in a whole new direction? also here is my rotation reset code.
playerCamera.transform.rotation.y = 0;
playerCamera.transform.rotation.z = 0;
player.transform.rotation.y = 0;
player.transform.rotation.z = 0;