I did a little playing around.
In this situation where you want to do the same thing on both sides, it's easier to have the -180 +180 discontinuity below instead of to the left like in Godot's lookat function, then correct it at the end after all the clamping and stuff.
extends Sprite
var mouse_up = 60 # Degrees you can loop up
var mouse_down = 10 # Degrees you can look down
onready var playerbody = $ThePlayer
onready var pivot = $Pivot
onready var Head = $ThePlayer/MainCharacterBody/MainCharacterHead
func _ready():
pass
func _physics process(delta):
var mouselocation = get_global_mouse_position() - playerbody.position
var angle=0.0
# Get angle in degrees from up. Negative angles are to the left, positive to the right.
angle = rad2deg(atan2(mouselocation.x,-mouselocation.y))
# Use the absolute of the angle (so works for left and right) to clamp, then use sign to get back to left and right.
angle = clamp(abs(angle),90-mouse_up,90+mouse_down)*sign(angle)
# Godot wants 0 degrees to face right, but our's faces up, so add 90 degrees
rotation_degrees = angle+90
if mouselocation.x > 0:
# If on the right, add 180 degrees to not be upsidedown, and flip.
rotation_degrees = 180 + rotation_degrees
flip_h = true
else:
flip_h = false
I changed the min and max to up and down to make it clearer what they did.
This is it with 10 degrees down and 60 degrees up.