Code: Select all
TrackUnit = function(unitID)
local paused = select(3, spGetGameSpeed())
local velPredict = paused and 0 or 2
local cam = {}
local oldcam = spGetCameraState()
local tx, ty, tz = spGetUnitViewPosition(unitID, true)
--local vx, vy, vz = spGetUnitDirection(unitID)
--local rotX, rotY, rotZ = GetRotationFromVector(vx, vy, vz)
local velocity = {spGetUnitVelocity(unitID)}
local dist = thirdPerson_dist
local pitch = thirdPerson_pitch -- + (overview_mode and 0 or rotX)
local yaw = thirdPerson_heading -- + (overview_mode and 0 or rotY)
local targetPos = {
tx - math.sin(yaw) * math.cos(pitch)*dist + velocity[1]*velPredict,
ty + math.sin(pitch) * dist + velocity[2]*velPredict,
tz - math.cos(yaw) * math.cos(pitch)*dist + velocity[3]*velPredict,
}
local deltaPos = {
targetPos[1] - oldcam.px,
targetPos[2] - oldcam.py,
targetPos[3] - oldcam.pz,
}
cam.px = targetPos[1]
cam.py = targetPos[2]
cam.pz = targetPos[3]
--cam.vx = p.velocity[1]*Game.gameSpeed
--cam.vy = p.velocity[2]*Game.gameSpeed
--cam.vz = p.velocity[3]*Game.gameSpeed
cam.rx = 0-pitch
cam.ry = yaw
cam.rz = thirdPerson_roll
spSetCameraState(cam, 0.5)
end
So, two questions:
1) Would it work better if there was a way to make SetCameraState (and SetCameraTarget) move at a constant speed, rather than start out fast and slow down as it approaches the new camera position?
2) How to solve/work around this problem without (1)?
I could do it easily, if I knew how to make trackmode in free camera mode automatically move with the tracked unit, as it does in the other camera modes.