Skip to content

Instantly share code, notes, and snippets.

@happyharis
Created April 9, 2018 05:00
Show Gist options
  • Save happyharis/bb61c8585dd3b94511e3c08fd592bfa4 to your computer and use it in GitHub Desktop.
Save happyharis/bb61c8585dd3b94511e3c08fd592bfa4 to your computer and use it in GitHub Desktop.
Player motor and controller part 3
// Player Motor
private Vector3 cameraRotation = Vector3.zero;
public void RotateCamera(Vector3 _cameraRotation){
cameraRotation = _cameraRotation;
}
void PerformRotation () {
rb.MoveRotation (rb.rotation * Quaternion.Euler (rotation));
if (cam != null)
{
cam.transform.Rotate (-cameraRotation);
}
}
// Player Controller
// Calculate camera rotation as a 3D vector
float _xRot = Input.GetAxisRaw("Mouse Y");
Vector3 _cameraRotation = new Vector3 (_xRot, 0f, 0f) * lookSensitivity;
// Apply camera rotation
motor.RotateCamera(_cameraRotation);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment