#[Lua Cutscenes] How to zoom on the center of the player ?

20 messages · Page 1 of 1 (latest)

frail crown
#

I'd like to have a Lua Cutscenes zoom on the player, then dezoom (the lua cutscene trigger is placed on the player's spawnpoint of the first room of the map, so that when you enter the map, the cutscene activates automatically). I know (I think) how to zoom and dezoom, but it still zooms in another place, to the bottom right of the player for some reason

I didn't manage to do it. If someone knows, a little help would be great 🙂

function onBegin(room)
    disableMovement()
    
    -- Gets player position
    local player_pos = player.Position
    
    -- Zoom in at the start of the level and zooms out in 4 seconds, after 2 seconds of being zoomed in
    engine.Scene:ZoomSnap(player_pos, 3)
    wait(2)
    coroutine.yield(engine.Scene:ZoomBack(4))
    
    
end
#

(If any detail is needed or I forgot anything, please let me know)

rocky vortex
#

if it zooms in bottom right of the player best solution is just use something like player_pos.x = player_pos.x - <some number which should be half of the player's width> and same for height catblob

frail crown
#

wouldn't be that considered "bad" ? as in, using some arbitrary numbers, wouldn't it cause any issues ?

#

oh sorry, I said bottomright of the player, I meant the bottom right of the screen...

rocky vortex
#

oh, makes sense

#

because player's position is counted from bottom center iirc

#

so.. it's not same position as anything else (but theo crystal iirc)

#

so ig only solution is to use something like i said above

#

you need somehow to convert player's position to normal position

#

but idk anything about them so wait for someone smarter than me catbus

frail crown
rocky vortex
#

probably corner because number is out of bounds

#

should be far away

frail crown
#

So yeah you were right, I think ! Here's my "working" code : ```lua
local tile_size = 8
local tile_width = 40

local window_width = tile_width * tile_size

local player_pos = player.Position
local cam_pos = getLevel().Camera.Position

local move_vector = vector2(player_pos.x - window_width / 1.5, cam_pos.y)

log(player_pos)
log(cam_pos)

-- Zoom in at the start of the level and zooms out in 4 seconds, after 2 seconds of being zoomed in
wait(3)
coroutine.yield(engine.Scene:ZoomTo(move_vector, 5, 4))
wait(2)
coroutine.yield(engine.Scene:ZoomBack(4))
rocky vortex
#

ig 40 is tiles count. I think there is some way to get roomWidth :>

#

But i'm not sure

#

you probably shouldn't add resolved tag yet, cuz i'm pretty sure your code is not perfect, and someone knows way to improve it

#

but use it for now (if it works)

frail crown