Changes in GetCameraState/SetCameraState

Changes in GetCameraState/SetCameraState

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
MelTraX
Posts: 470
Joined: 02 Jan 2007, 16:18

Changes in GetCameraState/SetCameraState

Post by MelTraX »

I noticed that my "go to unit" didn't work anymore. The reason is changes in GetCameraState and SetCameraState that I couldn't find in the changelog. Maybe they are listed somewhere else but I thought I just post them here anyway.

The old return value of GetCameraState was a numerically indexed table with the position and some other info.

The new return value is a table with string indices (dx, dy, dz, flipped, height, mode, name, px, py, pz, zscale).

So if you just want to go to a unit:

Code: Select all

local currentCamState = Spring.GetCameraState()
local x, y, z = Spring.GetUnitPosition(yourUnitIDHere)

currentCamState.px = x
currentCamState.pz = z

Spring.SetCameraState(currentCamState, 1)
Hope this helps anyone..
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: Changes in GetCameraState/SetCameraState

Post by Beherith »

I use Spring.SetCameraTarget(x,y,z,t) to go to units. Its nice cause it doesnt change zoom level or anything, just the focal point.
MelTraX
Posts: 470
Joined: 02 Jan 2007, 16:18

Re: Changes in GetCameraState/SetCameraState

Post by MelTraX »

Nice, didn't know about that one.. That reduces the code in the first post to:

Code: Select all

Spring.SetCameraTarget(Spring.GetUnitPosition(yourUnitIDHere))
The forth parameter doesn't seem to exist though.. And I still think that the changes in GetCameraState/SetCameraState were undocumented so this topic might still have a purpose :P..
Post Reply

Return to “Lua Scripts”