Camera Help

Hi All!

I am new to Defold and have been following the tutorials / reading the documentation. However, I’m still having issues with getting the Orographic camera to work. No matter what I try it doesn’t work (the view stays the same and it doesn’t zoom in).

Here is my main.collection:

image

Here’s my camera script:

  • function init(self)
  • msg.post("/camera#camera", “aquire_camera_focus”)
  • end

Here’s in the default.render_script script:

  • msg.post("@render:", “use_camera_projection”)

Here are my Camera properties:

image

Here are my Player properties:

image

Thanks!

I believe they said this one shouldn’t be needed any longer with the updated camera in defold. But I use this as it’s easier and better documented…

britzl/defold-orthographic: Orthographic camera functionality for the Defold game engine (github.com)

Thank you! I thought about using that one but always like to learn how things work before jumping into another person’s library.

britzl works for defold. I think a lot of the features in this camera made it into the current defold camera.

You should put this in the camera.script.

You have a typo in the message ID here, it’s missing the “c” in “acquire”.

I would also double-check that the URL is correct. Since the script is on the same object as the camera component, you should be able to just do “#camera”. But you can check the absolute URL of the object by doing:

print(msg.url())
1 Like

Oh my gosh… I must have looked at that line of code for hours without realizing the typo haha.

Thank you, both!

The camera is now working as intended.

Actually, now that I have the camera working how I want it I noticed another issue.

My character’s sprite shows up twice when the camera moves to follow him. It looks like I’m seeing double. When he is in the idle state I only see one of him.

Not sure if that is my sprite animations or the camera?

1 Like

Double check that your sprite component isn’t offset by half a pixel or something like that.

I described the same issue here:

Before 1.6.2 it worked flawlessly. Something changed and I can’t yet find out what. I noticed it because I had tutorial written ready in November for camera movement for Platformer, but when I tried to follow my own tutorial - I failed :sweat_smile: Before I needed only to attach camera and send the two messages, now it’s not the way :confused:

The “doubled” sprite is appearing really fast, because I can’t record it on screen, but I see it on my screen.

I recorded it though with phone:

Aa, ok - there seems to be issue here.

Position of hero game object (having camera inside) is changed over time with non-integer values. e.g.:

DEBUG:SCRIPT: vmath.vector3(510.33340454102, 256, 0) -- going right
DEBUG:SCRIPT: vmath.vector3(518.66674804688, 256, 0)
DEBUG:SCRIPT: vmath.vector3(527.00006103516, 256, 0)
DEBUG:SCRIPT: vmath.vector3(535.33337402344, 256, 0)
DEBUG:SCRIPT: vmath.vector3(535.33337402344, 265.72222900391, 0)  -- started jumping
DEBUG:SCRIPT: vmath.vector3(535.33337402344, 275.16668701172, 0)

Why it’s the issue now and wasn’t before 1.6.2?

1 Like