Page 1 of 1

[total newbie] GetPiecePosDir(attemp to call global)

Posted: 02 Mar 2013, 23:22
by tino415
Why I can't use GetPiecePosDir (attemp to call global). Is there any workoaround ?? Or i made any mistake ?

Code: Select all

local base = piece "base"
local ltracks = {}
local rtracks = {}
-- declares all the pieces we'll use in the script.

for i=0,42 do
	local tname = "lt" .. i
	ltracks[i] = piece (tname)
end

for i=0,42 do
	local tname = "rt" .. i
	rtracks[i] = piece (tname)
end

function script.StartMoving()
	movetrack()
end

function movetrack()
	local i = 0
	while true do
		local tx,ty,tz,rx,ry,rz = GetPiecePosDir ( rtracks[i+1] )
		Move(rtracks[i], x_axis, tx, 4)
		Move(rtracks[i], y_axis, ty, 4)
		Move(rtracks[i], z_axis, tz, 4)
		if i == 42 then break
		else i=i+1 end
	end
end

function script.Create()
    return 0
end
function script.Killed(recentDamage, maxHealth)
	return 0
end

function script.HitByWeapon(x,z,weaponDef,damage)
    -- This stops the unit taking damage until it's been built.
	if GetUnitValue(COB.BUILD_PERCENT_LEFT)>2 then return 0
	else return damage
	end
end

Re: [total newbie] GetPiecePosDir(attemp to call global)

Posted: 03 Mar 2013, 01:28
by FLOZi
Spring.GetPiecePosDir

Re: [total newbie] GetPiecePosDir(attemp to call global)

Posted: 03 Mar 2013, 09:09
by tino415
FLOZi wrote:Spring.GetPiecePosDir
I get error "attempt to call field...", :(

Re: [total newbie] GetPiecePosDir(attemp to call global)

Posted: 03 Mar 2013, 10:55
by FLOZi
I'm a muppet, didn't realise that function is in LUS itself:

Spring.UnitScript.GetPiecePosDir

Only certain functions are automagically localised for LUS scripts:

https://github.com/spring/spring/blob/d ... header.lua

Re: [total newbie] GetPiecePosDir(attemp to call global)

Posted: 03 Mar 2013, 12:55
by tino415
FLOZi wrote:I'm a muppet, didn't realise that function is in LUS itself:

Spring.UnitScript.GetPiecePosDir

Only certain functions are automagically localised for LUS scripts:

https://github.com/spring/spring/blob/d ... header.lua
Thank's

Re: [total newbie] GetPiecePosDir(attemp to call global)

Posted: 03 Mar 2013, 12:56
by tino415

Code: Select all

local rtracks = {}
local GetPieceTranslation = UnitScript.GetPieceTranslation
-- declares all the pieces we'll use in the script.

for i=0,42 do
	local tname = "lt" .. i
	ltracks[i] = piece (tname)
end

for i=0,42 do
	local tname = "rt" .. i
	rtracks[i] = piece (tname)
end

function script.StartMoving()
	movetrack()
end

function movetrack()
	local i = 0
	while (true) do
		-- local atx,aty,atz = UnitScript.GetPieceTranslation ( rtracks[i] )
		local tx,ty,tz = GetPieceTranslation ( rtracks[i+1] )
		Move(rtracks[i], x_axis, tx, 5)
		Move(rtracks[i], y_axis, ty, 5)
		Move(rtracks[i], z_axis, tz, 5)
		if i == 41 then 
			local tx,ty,tz = GetPieceTranslation ( rtracks[0] )
			Move(rtracks[42], x_axis, tx, 1.2)
			Move(rtracks[42], y_axis, ty, 1.2)
			Move(rtracks[42], z_axis, tz, 1.2)
			break
		else i=i+1 end
	end
end

function script.Create()
    return 0
end
function script.Killed(recentDamage, maxHealth)
	return 0
end

function script.HitByWeapon(x,z,weaponDef,damage)
    -- This stops the unit taking damage until it's been built.
	if GetUnitValue(COB.BUILD_PERCENT_LEFT)>2 then return 0
	else return damage
	end
end
I want to get track possition and next track position and then move track 1 to possition of track 2, but it seems not working... Why ??

Re: [total newbie] GetPiecePosDir(attemp to call global)

Posted: 03 Mar 2013, 13:21
by knorke
The idea is good, has potential :)
but it seems not working... Why ??
hm one thing is you need some Sleep() or WaitForMove() function to give the pieces time to float to their new positions.
Is there an error message or problem with logic? Errors are logged here:
http://springrts.com/wiki/Infolog.txt

if you upload mod with model it is easier for others to test

Re: [total newbie] GetPiecePosDir(attemp to call global)

Posted: 03 Mar 2013, 15:09
by FLOZi
Even an image of the model would be useful here - the biggest question is 'is it worth doing something this complex?'

Re: [total newbie] GetPiecePosDir(attemp to call global)

Posted: 03 Mar 2013, 19:50
by tino415
Here is the mod, it's only for experimenting(i'm doing litle research how many time what takes), unit name is tracker, and it can't by builded, this mod I have only for experimenting, I'm think, there I can use animation script's from spring tanks, but in game i preparing to do I gona need more complex shapes of tracks then two wheel on one site :-D

Re: [total newbie] GetPiecePosDir(attemp to call global)

Posted: 04 Mar 2013, 01:25
by knorke
oh something just come to my mind to consider4:
Move command is relative to pieces original position, as is GetPiecePosDir iirc.
So if you do
local tx,ty,tz,rx,ry,rz = GetPiecePosDir ( rtracks[i+1] )
it will return 0,0,0,0,0,0

Re: [total newbie] GetPiecePosDir(attemp to call global)

Posted: 04 Mar 2013, 18:42
by tino415
knorke wrote:oh something just come to my mind to consider4:
Move command is relative to pieces original position, as is GetPiecePosDir iirc.
So if you do
local tx,ty,tz,rx,ry,rz = GetPiecePosDir ( rtracks[i+1] )
it will return 0,0,0,0,0,0
Is there a way to get possition relative to parent piece ??
So I gona need to do full possition table...

Re: [total newbie] GetPiecePosDir(attemp to call global)

Posted: 04 Mar 2013, 18:49
by FLOZi
tino415 wrote:
knorke wrote:oh something just come to my mind to consider4:
Move command is relative to pieces original position, as is GetPiecePosDir iirc.
So if you do
local tx,ty,tz,rx,ry,rz = GetPiecePosDir ( rtracks[i+1] )
it will return 0,0,0,0,0,0
Is there a way to get possition relative to parent piece ??
Spring.UnitScript.GetPieceTranslation ( piece ) -> number x, y, z

c.f. http://springrts.com/wiki/Animation-LuaCallouts

Re: [total newbie] GetPiecePosDir(attemp to call global)

Posted: 04 Mar 2013, 21:16
by tino415
FLOZi wrote:
tino415 wrote:
knorke wrote:oh something just come to my mind to consider4:
Move command is relative to pieces original position, as is GetPiecePosDir iirc.
So if you do
local tx,ty,tz,rx,ry,rz = GetPiecePosDir ( rtracks[i+1] )
it will return 0,0,0,0,0,0
Is there a way to get possition relative to parent piece ??
Spring.UnitScript.GetPieceTranslation ( piece ) -> number x, y, z

c.f. http://springrts.com/wiki/Animation-LuaCallouts
But it also return zeros, so im think it is also onli detect changes agains standard possitions...

Re: [total newbie] GetPiecePosDir(attemp to call global)

Posted: 06 Mar 2013, 03:47
by knorke
There is no function to get piece position relative to unit center, unless I missed something here.

The idea of making each piece float to position of previous piece has some elegance but without easy "GetPiecePositionRelativeToUnitCenter" function realising it seems a bit cumbersome.

There is Spring.GetUnitPiecePosDir which gives the piece position in world coordinates. So one could also get unit position, and from those two calculate what you need, but watch out that you also have to take into account unit rotation around all axis.

Instead you could try setting up a table of "waypoint positions"
like
trackPosition[1] = {x=100, z=200}
trackPosition[2] = {x=110, z=205}
trackPosition[3] = {x=115, z=210}
...
and then have the piece float to next waypoint like
Move (ltracks , x_axis, trackPosition[t].x)

But how to get the waypoints without trial&error?
1) Make script that exports piece positions of spawned unit. If you spawn the unit at 0,0,0 with correct rotation, GetPiecePositionRelativeToUnitCenter is easy to calculate.

2) The units track pieces must be at correct waypoint position before export - how?
Either by setting them in 3d editor or via a simple script or with
unit poser