I’m trying to implement this in a project. It is where when you zoom in on a map or something your cursor remains at the location of a thing it is hovering. Try Google Maps to remember how that works.
These seem like the steps needed to get the zoom to cursor to work
- Get rendercam.screen_to_world_2d
- Adjust camera zoom amount
- Get rendercam.screen_to_world_2d again
- Move camera based on the difference of world position of cursor
But if I do that in a frame it doesn’t seem to work. I tried with two cameras as well.
local function rendercam_test()
go.set_position(vmath.vector3(0,0,0), "camera")
local position_1 = rendercam.screen_to_world_2d(0, 0, false, nil, false)
go.set_position(vmath.vector3(100,100,0), "camera")
local position_2 = rendercam.screen_to_world_2d(0, 0, false, nil, false)
print(position_1, position_2)
end
local function rendercam_test2()
rendercam.activate_camera(go.get_id("camera"))
rendercam.pan(100, 100, go.get_id("camera"))
local position_1 = rendercam.screen_to_world_2d(10, 10, false, nil, false)
rendercam.activate_camera(go.get_id("camera_secondary"))
rendercam.pan(10000, 10000, go.get_id("camera_secondary"))
local position_2 = rendercam.screen_to_world_2d(10, 10, false, nil, false)
print("Difference", position_2 - position_1)
print(position_1, position_2)
print(go.get_position("camera"), go.get_position("camera_secondary"))
rendercam.activate_camera(go.get_id("camera"))
end
Should this work? Or is there something simple I’m missing/forgetting?