Page 1 of 1

Camera stuttering at close range

Posted: 16 May 2013, 17:04
by KingRaptor
So I have some code to make the camera follow a unit, like thus:

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
Problem: the camera stutters visibly when used close up, as seen here (some of it is from lag during the recording, but not all). Lowering the camTime in SetCameraState makes it worse, raising it reduces the stuttter but doesn't eliminate it (and reduces the responsiveness of the camera).

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.

Re: Camera stuttering at close range

Posted: 16 May 2013, 17:54
by smoth
this isn't the whole script. may i see the whole script?

Re: Camera stuttering at close range

Posted: 16 May 2013, 18:02
by KingRaptor
ok

warning: spaghetti as hell

Re: Camera stuttering at close range

Posted: 16 May 2013, 18:03
by zwzsg
Why don't you simply use Spring.SendCommands("track") ?

Re: Camera stuttering at close range

Posted: 16 May 2013, 18:26
by KingRaptor
zwzsg wrote:Why don't you simply use Spring.SendCommands("track") ?
Because it remains in a fixed position instead of following the unit in free camera mode.

(course, I could modify the code to use rotatable overhead instead of free cam, which I'll try once I figure out the damn camstate variables for that camera mode)

Re: Camera stuttering at close range

Posted: 16 May 2013, 18:50
by zwzsg
If you want to smoothly follow a unit of potentially erratic motion, I guess you have to learn automatism.

Re: Camera stuttering at close range

Posted: 17 May 2013, 15:50
by jK
2 things:
1. using spGetUnitVelocity(unitID) is not continuous, also velocity extrapolation is already done in GetUnitViewPosition
2. using camTime !=0 neither (when called each drawframe)

Re: Camera stuttering at close range

Posted: 27 May 2013, 16:54
by KingRaptor
(course, I could modify the code to use rotatable overhead instead of free cam[...])
Turns out to have been a bad idea (rotatable overhead assumes the camera is, well, overhead, and keeps the camera directly over the unit regardless of where it's facing)

Can I just make a feature request to have free camera in track mode match the unit's movements, like every other camera mode does?