Your camera script is based around the center of the screen, but you have tried to center it around something else (a character at the bottom left). You will have to change your algorithm to include the player’s position and maybe even global coordinates.
Heya, after month “of doing nothing” i did that dynamic camera!
For him need:
Node2D (Or other main node)
Camera2D (CoPO)
CharacterBody2D (PoPO)
First, we need add in “CharacterBody2D” this code:
extends CharacterBody2D
# Exporting coordinates of position CharacterBody2D
@export var popoPos = Vector2()
func _process(delta):
# Updating positions of player
popoPos.x = global_position.x
popoPos.y = global_position.y
Next, we need add that code in “Node2D”:
extends Node2D
func _process(delta):
var mouse_position = get_global_mouse_position() #Getting mouse positions
var cameraPoPOpos = $PoPO #Camera of CharacterBody2D position = CharacterBody2D
var target_position = (cameraPoPOpos.get("popoPos") + mouse_position) / 2 #Calculating middle position of mouse and character
$CoPO.global_position = target_position #Setting global position of Camera2D
# print (target_position) #Printing in console middle position of camera
And you get full working camera what following to mouse from player! :3