Camera stuttering at close range

Camera stuttering at close range

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

Moderator: Moderators

Post Reply
User avatar
KingRaptor
Zero-K Developer
Posts: 838
Joined: 14 Mar 2007, 03:44

Camera stuttering at close range

Post 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.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Camera stuttering at close range

Post by smoth »

this isn't the whole script. may i see the whole script?
User avatar
KingRaptor
Zero-K Developer
Posts: 838
Joined: 14 Mar 2007, 03:44

Re: Camera stuttering at close range

Post by KingRaptor »

ok

warning: spaghetti as hell
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Camera stuttering at close range

Post by zwzsg »

Why don't you simply use Spring.SendCommands("track") ?
User avatar
KingRaptor
Zero-K Developer
Posts: 838
Joined: 14 Mar 2007, 03:44

Re: Camera stuttering at close range

Post 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)
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Camera stuttering at close range

Post by zwzsg »

If you want to smoothly follow a unit of potentially erratic motion, I guess you have to learn automatism.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Camera stuttering at close range

Post 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)
User avatar
KingRaptor
Zero-K Developer
Posts: 838
Joined: 14 Mar 2007, 03:44

Re: Camera stuttering at close range

Post 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?
Post Reply

Return to “Lua Scripts”