Modding Help Localanimator problem when 2000 > x > 1490 (solved)

Discussion in 'Starbound Modding' started by Rezetrx, Sep 13, 2022.

  1. Rezetrx

    Rezetrx Void-Bound Voyager

    I am currently working on a weapon from the game Destiny, the sleeper simulant.
    Firing the weapon shoots three projectiles which send their previous and new position back to the player. The weapon then handles the two positions as line. The weapons animation script then handles the creation of lines between the two positions.
    This works fine on my first test character but on my second character, something weird occurs. when the laser hits the position where x = 0, for some reason the drawn laser bounces, yet the projectiles (which deal the damage and return the positions for the laser drawable, continues on as intendet. upload_2022-9-13_23-43-57.png

    The area the bounce occurs is at x=3000 and I've flown over the planet to the left until about x:1490.
    Within these ~500 blocks the drawable is not created at all and no error gets returned in the console.

    Now what confuses me the most is, that when the projectile traverses the border from x:0 to x:3000 that the segments it tries to draw would be weird (start at {3,700} and ends at {3000, 700}) but further down the line (like 2000 to 1990) it should work normally, but it doesn't

    My question now is, does anyone know why or how this could happen and how I could go about fixing it.

    Here is the code for my animator script
    Code:
    require "/scripts/util.lua"
    require "/scripts/vec2.lua"
    
    function init()
    end
    
    function update()
        localAnimator.clearDrawables()
      
        local lineArray1 = animationConfig.animationParameter("list1") or {}
        local lineArray2 = animationConfig.animationParameter("list2") or {}
        local lineArray3 = animationConfig.animationParameter("list3") or {}
      
        drawLines(lineArray1)
        drawLines(lineArray2)
        drawLines(lineArray3)
      
    end
    
    function drawLines(array)
            if #array >0 then
            for i=1, #array do
                sb.logInfo("array" .. i .. " pos: " .. vec2.print(array[i][1], 2) .. " // " .. vec2.print(array[i][2],2))
                local drawable = {
                    line = array[i],
                    width = 3,
                    color = "#ff3300",
                    fullbright = true
                }
                localAnimator.addDrawable(drawable, "player-1")
            end
        end
    end
    
    Here the script of the projectile
    Code:
    require "/scripts/vec2.lua"
    
    
    function init()
        self.paramKey = config.getParameter("paramKey")
        self.bounceDMGfactor = config.getParameter("bounceDMGfactor") or 0.75
        self.posList = {}
        self.lastPos = mcontroller.position()
        self.firstCollision = false
    end
    
    function update(dt)
        if mcontroller.isColliding() then
            if not self.firstCollision then
                projectile.setPower(projectile.power() * self.bounceDMGfactor)
                self.firstCollision = true
            end
        end
            newPosition()
    end
    
    
    function uninit()
        --sb.logInfo("position of uninit: " .. vec2.print(mcontroller.position(),2))
        newPosition()
    end
    
    
    function newPosition()
        local newLine = { self.lastPos, mcontroller.position()}
        table.insert(self.posList, newLine)
        self.lastPos = mcontroller.position()
        sendMssageToWeapon()
    end
    
    function sendMssageToWeapon()
        world.sendEntityMessage(projectile.sourceEntity(), "sleeperlaserBounce", self.paramKey, self.posList)
    end
    
    function trigger()
        projectile.die()
    end
    
    And lastly for the weapon script, the important parts that link the previous two scripts
    Code:
    
    message.setHandler("sleeperlaserBounce", function(_, _, key, poslist)
            if self.activeDrawing then
                if key == 1 then
                    self.linearray1 = poslist
                elseif key == 2 then
                    self.linearray2 = poslist
                elseif key == 3 then
                    self.linearray3 = poslist
                else
                    sb.logInfo("[Sleeper]: Unknown message key:" .. key or "nil")
                end
            end
        end)
    
    ...
    
            activeItem.setScriptedAnimationParameter("list1", self.linearray1)
            activeItem.setScriptedAnimationParameter("list2", self.linearray2)
            activeItem.setScriptedAnimationParameter("list3", self.linearray3)
    
    
    Edit: the value of x is actually 3000 not 2000. Meaning that the laser is rendered one side of the planet, yet not the other...
     
    Last edited: Sep 13, 2022
  2. Rezetrx

    Rezetrx Void-Bound Voyager

    I did some fiddling with coordinates and it turns out that the drawable works on a 50/50 positive/negative coordinate system.

    Code:
    function drawLines(array, plPos)
        if #array >0 then
            for i, drawLine in ipairs(array) do
            --sb.logInfo("drawLine1: " .. vec2.print(drawLine[1] or {0,0}, 2))
            --sb.logInfo("drawLine2: " .. vec2.print(drawLine[2] or {0,0}, 2))
                if plPos[1] > world.size()[1]/2 then
                    plPos[1] = -world.size()[1]/2+ (plPos[1] - world.size()[1]/2)
                end
                local dist1 = world.distance(plPos, drawLine[1])
                local dist2 = world.distance(plPos, drawLine[2])
    
                local drawable = {
                    line = {
                        vec2.add(plPos,vec2.mul(dist1,-1)),
                        vec2.add(plPos,vec2.mul(dist2,-1))
                    },
                    width = 3,
                    color = "#ff3300",
                    fullbright = true
                }
                localAnimator.addDrawable(drawable, "player-1")
                world.debugLine(
                    vec2.add(plPos,vec2.mul(dist1,-1)),
                    vec2.add(plPos,vec2.mul(dist2,-1)),
                    "#00ff00")
                world.debugLine(
                    drawLine[1],
                    drawLine[2],
                    "#ff00ff")
            end
        end
    end
    The key change is this part
    Code:
                
    if plPos[1] > world.size()[1]/2 then
    [INDENT]plPos[1] = -world.size()[1]/2+ (plPos[1] - world.size()[1]/2)[/INDENT]
    end
    
     

Share This Page