How to make the camera rotate towards the player's movement?

Hey everyone. I recently started learning Godot 4 (two weeks to be exact) and encountered a problem with the camera turning towards the player’s movement. I study programming purely for the hobby, so I don’t really understand it, although I’m really trying to learn it. I wrote a simple script and it almost works, but the transition between the right and top sides is abrupt for obvious reasons. I have already looked through many sources, but either there is not what I need, or the explanation is too complex. I would be grateful to anyone who can help me with this problem.

func _process(_delta: float) -> void:
	if Input.is_action_pressed("ui_left"):
		rotation_degrees.y += 0.5
		if rotation_degrees.y > 0:
			rotation_degrees.y = 0
		#print(rotation_degrees.y)
	if Input.is_action_pressed("ui_right"):
		rotation_degrees.y -= 0.5
		if rotation_degrees.y < -180:
			rotation_degrees.y = -180
		#print(rotation_degrees.y)
	if Input.is_action_pressed("ui_up"):
		rotation_degrees.y -= 0.5
		if rotation_degrees.y < -90:
			rotation_degrees.y = -90
		#print(rotation_degrees.y)
	if Input.is_action_pressed("ui_down"):
		rotation_degrees.y += 0.5
		if rotation_degrees.y > 90:
			rotation_degrees.y = 90
		#print(rotation_degrees.y)

You can download and learn from this plugin. It is open source, so you can see how they did what they did. There are other cameras in the asset store you can look at as well.

https://godotengine.org/asset-library/asset/3242

Repo for the above camera:

Edit: apologies for what I consider a “lazy” answer, if I had more time I would do a deeper dive in your code.

Perhaps another day. Either way, I thoight the above repo would be useful for you to look over.

1 Like

nutlike4693, thank you very much, but this is not what I need, although I will also need it in the future.