So I’m trying to center my character in the view of a camera that follows as they move; and yes I’ve looked at previous threads, but I’m asking for help here as I still don’t understand how to position my camera properly. I’ve “childed” to the game object I want it to follow, and it does work in that sense, however my character is in the bottom left corner of the camera view.
I understand that I have to somehow offset the camera from reading other threads, but I still don’t know how to do that.
You can read the width and height of the screen and move the camera by half those values:
local w = tonumber(sys.get_config("display.width"))
local h = tonumber(sys.get_config("display.height"))
go.set_position(-vmath.vector3(w/2, h/2, 0), "camera")
You need to have your camera component on its own game object, and move that object. You can’t change the position of components at runtime. (The camera component doesn’t have its own position in the editor either.)
If you’re getting a nil vector, try printing out w and h to see if they are correct.
You’ll need to be using a collection file to have multiple game objects (parent-child, etc.), “.go” files are only for a single game object. Generally you should just use Collections for everything, unless it’s a really simple object like a bullet or something.
No, not unless you want to do something more fancy with it. Or if you just want to keep its stuff separate—but making a separate script for three lines of code seems a bit silly.
Okay, I’m still not sure why vector3 still comes up as a nil value? It seems like it should work, but I’m guessing w, and h can’t be found or something like that. Any ideas?
(Edit) It’s fixed, was just a small error on my end! thank you so much ^^