View Issue Details

IDProjectCategoryView StatusLast Update
0001527FSSCPscriptingpublic2008-03-23 12:36
ReporterNuke Assigned ToWMCoolmon  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.6.9 
Fixed in Version3.6.10 
Summary0001527: Subsystem.Position returns incorrect values
DescriptionSubsystem.Position seems to return the wrong values. cycling through subsystems usually result in the same coords for each per ship. selecting a different ship usually gives a different set of coords but they are also the same no matter which subsystem is selected. the coords also dont seem to match any of the subsystem coords from the models. looks to me like a pointer issue (random data).

see script in additional info, the value is used on line 99. the script in an upgrade to my lead indicator, i was trying to make it take subsystems into consideration. target a ship and cycle through subsystems. you will find the numbers prited on screen are always the same yet the subsystem name properly displayed.
Additional Information#Global Hooks ;;nukelead
$GameInit:
[

--all this stuff is for multires support, for getting true width and height, and for generating factors to scale coords by

w = gr.getScreenWidth()
h = gr.getScreenHeight()
cx = w/2
cy = h/2

if w >= 1024 then
    wf = w / 1024
    hf = h / 768
    awh = (wf + hf) / 2
    hires = true
else
    wf = w / 640
    hf = h / 480
    awh = ((wf + hf) / 2) * 0.625
    hires = false
end

--now that were done with that shit, we can define some more important vars

chr = 50
chg = 50
chb = 50
cha = 50

--now a crosshair, il make this much more detailed later, with target direction and orientation, target iff and maybe ammo gauge and locked/locking indicators

drawgunsight = function(x,y,x2,y2,r,g,b,a)
    local xd,yd = x-x2, y-y2
    local ld = math.sqrt(xd*xd+yd*yd)
    if ld > 128 then ld = 128 end
    
    gr.setColor(r,g,b,ld)
    gr.drawCircle(25,x,y)
    gr.setColor(r,g,b,200)
    gr.drawGradientLine(x+18,y+18,x+5,y+5)
    gr.drawGradientLine(x-18,y+18,x-5,y+5)
    gr.drawGradientLine(x+18,y-18,x+5,y-5)
    gr.drawGradientLine(x-18,y-18,x-5,y-5)
    gr.drawLine(x,y,x2,y2)
end

--enemy position, enemy velocity, weapon firing position, weapon velocity
nukelead = function(epos, evel, wpos, wvel) --pretty much the same math as wandereds, but reduced in size
    local vlen = evel:getMagnitude()
    local edis = wpos - epos
    local dlen = edis:getMagnitude()
    local trig = edis:getDotProduct(evel)
    local a = (wvel^2) - (vlen^2)
    local b = trig * 2
    local c = -(dlen^2)
    local d = (b^2) - 4 * a * c

    if d >= 0 and a ~= 0 then
        local m1 = ( -b + math.sqrt(d) ) / ( 2 * a)
        local m2 = ( -b - math.sqrt(d) ) / ( 2 * a)

        if (m1 >= 0 and m1 <= m2 and m2 >= 0) or (m1 >= 0 and m2 < 0) then
            return epos + ( evel / (1 / m1) )
        elseif m2 >=0 then
            return epos + ( evel / (1 / m2) )
        else
            return epos
        end
    else
        return epos
    end
end
]
$HUD:
[

player = mn.Ships["Alpha 1"]

xtarg = cx --this is where our crosshair will want to be by default
ytarg = cy --same thing but a little bit more vertical
vtarg = nil
xship = cx
yship = cy
target = nil

if player:isValid() then
    target = player.Target
    local subtarget = player.TargetSubsystem

    local banks = player.PrimaryBanks --work on this
    local wep1 = banks['1']
    local wepvel = wep1.WeaponClass.Speed

    if target:isValid() then
        local vtarg = target.Position
        
        if subtarget:isValid() then --figure subsystem position into the equation if one is selected
            vtarg = vtarg + target.Orientation:unrotateVector(subtarget.Position)
            gr.drawString(subtarget.Name)
            gr.drawString(subtarget.Position.x)
            gr.drawString(subtarget.Position.y)
            gr.drawString(subtarget.Position.z)
        else
            gr.drawString("invalid subtarget")
        end
        
        if vtarg:getScreenCoords() ~= false then
            xship, yship = vtarg:getScreenCoords()
            xship = xship * wf
            yship = yship * hf
            local ltarg = nukelead(vtarg, target.Physics.Velocity, player.Position, wepvel)
            
            if ltarg:getScreenCoords() ~= false then
                xtarg, ytarg = ltarg:getScreenCoords()
                xtarg = xtarg * wf
                ytarg = ytarg * hf
                
                xtarg = cx + (xship - xtarg)
                ytarg = cy + (yship - ytarg)
            end
        end
    end
end

if target:isValid() == false then --color interpolation effect
    if chr > 50 then chr = chr - 1 elseif chr < 50 then chr = chr + 1 end
    if chg > 50 then chg = chg - 1 elseif chg < 50 then chg = chg + 1 end
    if chb > 50 then chb = chb - 1 elseif chb < 50 then chb = chb + 1 end
elseif target.Team.Name == "Hostile" or target.Team.Name == "Traitor" then
    if chr < 255 then chr = chr + 1 end
    if chg > 0 then chg = chg - 1 end
    if chb > 0 then chb = chb - 1 end
elseif target.Team.Name == "Friendly" then
    if chr > 0 then chr = chr - 1 end
    if chg < 255 then chg = chg + 1 end
    if chb > 0 then chb = chb - 1 end
elseif target.Team.Name == "Unknown" then
    if chr < 255 then chr = chr + 1 end
    if chg > 0 then chg = chg - 1 end
    if chb < 255 then chb = chb + 1 end
elseif target.Team.Name == "Neutral" then
    if chr > 0 then chr = chr - 1 end
    if chg > 0 then chg = chg - 1 end
    if chb < 255 then chb = chb + 1 end
else
    if chr > 128 then chr = chr - 1 elseif chr < 128 then chr = chr + 1 end
    if chg > 128 then chg = chg - 1 elseif chg < 128 then chg = chg + 1 end
    if chb > 128 then chb = chb - 1 elseif chb < 128 then chb = chb + 1 end
end

drawgunsight(xtarg, ytarg, xship, yship, chr, chg, chb, cha)

]
#End
TagsNo tags attached.

Activities

WMCoolmon

2007-11-26 03:10

developer   ~0008701

Nice comments, very technical. :P

I can't find anything in Position that would cause that, but it does look like TargetSubsystem might have an issue if the player doesn't actually have something targeted. Looks unrelated, but I'll check it out as well when I fix this.

WMCoolmon

2008-03-23 12:36

developer   ~0009019

Just fixed this one & committed to trunk. I did have to revise the script to take into account my fixing of getScreenCoords. ;) After that, I was able to determine that the problem was that the script was using the offset of the submodel, rather than the center of the subsystem. This was in an attempt to get collision working properly with subsystem translation. For subsystems without models (eg everything on fighters), the submodel offset wasn't set.

I switched this to the subsystem center, and it seems to work fine now.

Issue History

Date Modified Username Field Change
2007-11-25 21:07 Nuke New Issue
2007-11-25 21:07 Nuke Status new => assigned
2007-11-25 21:07 Nuke Assigned To => WMCoolmon
2007-11-26 03:10 WMCoolmon Note Added: 0008701
2008-03-23 12:36 WMCoolmon Status assigned => resolved
2008-03-23 12:36 WMCoolmon Fixed in Version => 3.6.10
2008-03-23 12:36 WMCoolmon Resolution open => fixed
2008-03-23 12:36 WMCoolmon Note Added: 0009019