Page 1 of 1

Lua script request.

Posted: 25 Oct 2009, 16:29
by smoth
Could someone write a script that locks the camera in TA camera at a specific zoom and rotation. Also could the camera stay locked on a specific unit?

Thanks in advance.

Re: Lua script request.

Posted: 25 Oct 2009, 16:56
by aegis
smoth wrote:could the camera stay locked on a specific unit?
doesn't one of the keyboard shortcuts do that? T?

Re: Lua script request.

Posted: 25 Oct 2009, 17:13
by smoth
it has a specific camera angle etc... not the one I wanted.

Re: Lua script request.

Posted: 25 Oct 2009, 23:39
by Blue_Falcon
You can change the angle using Ctrl+Mousewheel... Is that what you're after?

Re: Lua script request.

Posted: 26 Oct 2009, 00:33
by zwzsg
Don't post such an answer, or Smoth will raeg about how useless it is to post requests here again.

Re: Lua script request.

Posted: 26 Oct 2009, 00:36
by smoth
Blue_Falcon wrote:You can change the angle using Ctrl+Mousewheel... Is that what you're after?
does that lock the camera to taview? does it set distance/angle? Does it set the camera to follow a unit? No, that is just turning the ta camera.

I would not make this request if I didn't have a good reason.

Re: Lua script request.

Posted: 26 Oct 2009, 06:20
by Tribulex
smoth wrote:
Blue_Falcon wrote:You can change the angle using Ctrl+Mousewheel... Is that what you're after?
does that lock the camera to taview? does it set distance/angle? Does it set the camera to follow a unit? No, that is just turning the ta camera.

I would not make this request if I didn't have a good reason.
I think i know what this reason is.


I second this request, i want it too actually... you will received baked goods from both smoth AND me.

Re: Lua script request.

Posted: 04 Nov 2009, 01:28
by zwzsg
What is the unit you need the follow? How does widget (or gadget?) is given its ID? Will that unit change? Is it for a game where each player only has one unit? What if that unit die? Lock on death place or allow free roaming? The angle and height, hard coded or parametrable? Which way are passed the parameters? I assume some elasticity between the camera and unit movement would be nicer than stuttering?

From having tinkered with xyz's "spectator mode" widget, I know all you need is to periodically issue the commands:

Spring.SetCameraState({name=ta, mode=1, px=UnitX, py=0, pz=UnitZ, flipped=-1, dy=-0.9, zscale=0.5, height=999, dx=0, dz=-0.45}, TRANSITION_DURATION)
Spring.SelectUnitArray({UnitID})
Spring.SendCommands("track") -- "trackoff" is the command to stop it
Spring.SelectUnitArray({})

Or maybe if you're less conscious just:
Spring.SetCameraTarget(UnitX, 0, UnitZ, TRANSITION_DURATION)

So 90% of the code would be interfacing. And only you know what kind of interfacing you want. Because only you know the purpose and environnment of that Lua script.

Re: Lua script request.

Posted: 04 Nov 2009, 13:54
by KDR_11k
Should maybe mention that I already gave him one.

Re: Lua script request.

Posted: 14 Nov 2009, 02:42
by zwzsg
No, it was him that should have mentionned.



Here's the one I'm using now:

Code: Select all

	function gadget:Update()
		local u=GetTheOne()
		if u then
			-- Focus on the unit
			Spring.SelectUnitArray({},false)
			local x,_,z=Spring.GetUnitPosition(u)
			local _,v,paused=Spring.GetGameSpeed()
			v = paused and 0 or v
			local vx,_,vz=Spring.GetUnitVelocity(u)
			local r=UnitDefs[Spring.GetUnitDefID(u)].maxWeaponRange
			Spring.SetCameraState({name=ta, mode=1, px=x+9*v*vx,py=0, pz=z+9*v*vz, flipped=-1, dy=-0.9, zscale=0.5, height=2*r, dx=0, dz=-0.45},1)
		else
			if not Spring.GetSpectatingState() then
				-- Focus on the start pos
				Spring.SelectUnitArray({},false)
				local x,y,z=Spring.GetTeamStartPosition(Spring.GetLocalTeamID())
				Spring.SetCameraState({name=ta, mode=1, px=x, py=0, pz=z, flipped=-1, dy=-0.9, zscale=0.5, height=1200, dx=0, dz=-0.45},5)
			end
		end
	end
Notice how it compensate the unit speed and scale to weapon range. This does well for the purpose I wrote it for. However:






Is there any way to lock a camera, in the sense of making it obey Spring.SetCameraState and Spring.SetCameraTarget strictly and ignore any user input related to camera?

Because I want to do ingame cinematic intro to my mod, and I don't want my script to have to fight back against mouse pointer idling in the corner or user clicking on minimap.