Camera is not being positioned correctly

Hello, i’ve recently found Defold so I’m very new to Defold and I’ve been testing around and currently I’m trying to position the camera so the player is in the center of the screen (I have followed this tutorial to achieve this), I know that if I just position the camera to the player’s position the player would appear on the bottom left corner of the screen so I know I should offset the camera by half the screen width and height, but the player doesn’t appear in the center of the screen, I’ve been searching in the forums but I still have not found a solution to this problem. Here is a screenshot of how it looks:

And here’s the code that positions the camera:

function init(self)
	msg.post("#Camera", "acquire_camera_focus") 
end

function on_message(self, message_id, message, sender)
	if message_id == hash("follow") then 
		
		local width, height = window.get_size() 
		go.set_parent(".", sender) 
		go.set_position(vmath.vector3(-width/2, -height/2, 0)) 
	elseif message_id == hash("unfollow") then 
		go.set_parent("Camera", nil, true)
	end
end

Is there something I could do to position the camera properly?

Thanks in advance

Btw sorry for my bad english, english is not my main language :sweat_smile:

Hey! As you’re new to Defold I can assume you haven’t seen yet some ready libraries for camera manipulation. Here you have two:

In case you don’t know how to use projects as libraries, there is little manual for that:

Anyway there’s no need to get camera work on your own unless you’re doing it for learning purposes or need some more advanced stuff

3 Likes

Hello there,

I just wonder: the camera object in the tutorial you followed is called “camera”. In your code, the word is written with a capital “C”. Did you call your camera object “Camera” or “camera” (like in the tutorial). The words need to match.

1 Like