I use Javascript.
In my movement script I have a part about camera shake, but it isn’t working as I want.
The idea I use is adding a Vector3 to a variable called RotationImpact when getting attack, then applying it to the rotation and at the same time decreasing it. When the variable is equal to Vector3.zero I use an empty GameObject that is parented to the Player to get back slowly to the default look.
function FixedUpdate() {
...
// Camera lerp
if(RotationImpact == Vector3.zero){
Camera.main.transform.rotation = Quaternion.Euler(Vector3.Lerp(PlayerCamera.transform.eulerAngles, DefaultCamera.eulerAngles, 5*Time.deltaTime));
} else {
Camera.main.transform.rotation = Quaternion.Euler(RotationImpact);
RotationImpact = Vector3.Lerp(RotationImpact, Vector3.zero, 500*Time.deltaTime);
}
...
}
...
function AddCameraImpact() {
RotationImpact = new Vector3(0, 25, 25);
}
In the game the player gets hitted and the vector is stored in RotationImpact but the rotation is only applying in horizontal way. How could I make it rotate like if getting a diagonal hit?