Question Unable to switch VC cameras?

Thunder Chicken

Resident Lua Script Rabble-Rouser
Donator
Joined
Mar 22, 2008
Messages
5,847
Reaction score
5,509
Points
188
Location
Massachusetts
I have defined a simple VC that is intended to switch camera views between three seats in a row from left to right in a cockpit.

I have this code for

Code:
function clbk_loadVC(id)

    if id == 0 then

        vi:set_cameraoffset(camera_loc[1])
        vi:set_cameradefaultdirection(camera_dir[1])
        vi:set_cameramovement(_V(0,0,0.3), 0, 0, _V(-0.3,0,0), 75*RAD, -5*RAD, _V(0.3,0,0), -20*RAD, -27*RAD)
        oapi.VC_set_neighbours(-1, 1, -1, -1)

    elseif id == 1 then

        vi:set_cameraoffset(camera_loc[2])
        vi:set_cameradefaultdirection(camera_dir[2])
        vi:set_cameramovement(_V(0,0,0.3), 0, 0, _V(-0.3,0,0), 75*RAD, -5*RAD, _V(0.3,0,0), -20*RAD, -27*RAD)
        oapi.VC_set_neighbours(0, 2, -1, -1)

    elseif id == 2 then

        vi:set_cameraoffset(camera_loc[3])
        vi:set_cameradefaultdirection(camera_dir[3])
        vi:set_cameramovement(_V(0,0,0.3), 0, 0, _V(-0.3,0,0), 75*RAD, -5*RAD, _V(0.3,0,0), -20*RAD, -27*RAD)
        oapi.VC_set_neighbours(1, -1, -1, -1)

    end

end

Pressing F8 puts me in the left seat (id = 0) as expected. However, CTRL+ left/right arrow does not change the camera position to positions 1 or 2.

The camera positions and directions are defined as follows:

Code:
--Camera viewpoints

camera_loc = {}

camera_loc[1] = vec.sub({x=-0.2,y=0.3,z=1.5},cg)           --pilot seat (was on left side in R-4)
camera_loc[2] = vec.sub({x= 0.0,y=0.3,z=1.5},cg)           --centered seat
camera_loc[3] = vec.sub({x= 0.2,y=0.3,z=1.5},cg)           --right seat

camera_dir = {}

camera_dir[1] = get_help.rotate_pitch({x=0, y=0, z=1}, -20*RAD)
camera_dir[2] = get_help.rotate_pitch({x=0, y=0, z=1}, -20*RAD)
camera_dir[3] = get_help.rotate_pitch({x=0, y=0, z=1}, -20*RAD)

Changing the index manually does give me the correct camera. It simply does not cycle through the camera positions using the keyboard controls.

Any idea what I am missing?
 
Did you try returning true when the id is valid?
Yeah, I just realized that that was needed. I now have this and this switches the positions.

Code:
function clbk_loadVC(id)

    vi:set_cameramovement(_V(0,0,0.3), 0, 0, _V(-0.3,0,0), 75*RAD, -5*RAD, _V(0.3,0,0), -20*RAD, -27*RAD)
      
    if id == 0 then

        vi:set_cameraoffset(camera_loc[1])
        vi:set_cameradefaultdirection(camera_dir[1])
        oapi.VC_set_neighbours(-1, 1, -1, -1)

        return true

    elseif id == 1 then

        vi:set_cameraoffset(camera_loc[2])
        vi:set_cameradefaultdirection(camera_dir[2])
        oapi.VC_set_neighbours(0, 2, -1, -1)

        return true

    elseif id == 2 then

        vi:set_cameraoffset(camera_loc[3])
        vi:set_cameradefaultdirection(camera_dir[3])
        oapi.VC_set_neighbours(1, -1, -1, -1)

        return true

    else

        return false

    end

end

However, it seems that set_cameramovement isn't doing anything. I am unable to lean from each camera position.

EDIT: Nope, set_cameramovement does work, but the default CTRL + ALT + arrow conflicts with my OS hotkeys. I switched it in the Orbiter keymap to CTRL + SHIFT + arrow and it works appropriately.
 
Last edited:
One further question - is there a way to save the id of clbk_loadVC so if you toggle between the glass cockpit and the VC, that the last VC camera position is restored? Currently when you hit F8 to return back to the VC is sets the id back to 0. I've tried saving id to a global and then overriding id when the VC is restored but it doesn't seem to take.
 
One further question - is there a way to save the id of clbk_loadVC so if you toggle between the glass cockpit and the VC, that the last VC camera position is restored? Currently when you hit F8 to return back to the VC is sets the id back to 0. I've tried saving id to a global and then overriding id when the VC is restored but it doesn't seem to take.
Not sure, maybe with oapi.set_cameramode?
 
Not sure, maybe with oapi.set_cameramode?
This would basically mean not using a VC to specify camera positions. I suppose that would do it. There doesn't seem to be a way to tell clbk_loadVC to open a particular VC id.
 
Back
Top