Jump to content

havenphillip

Members
  • Posts

    550
  • Joined

  • Last visited

Posts posted by havenphillip

  1. Ah yes that worked perfectly, Ma-Shell. Thank you so much!
    GorzenDev that's the post I started from. The only thing was I needed to rotate the texture without rotating the quad/mask texture itself.
    Here's the script I'm using with the vertex and fragment of the shader for those wandering by:

    Script:

    Script.pos = Vec2(49,60) -- Vec2 "Position"
    Script.size = Vec2(210,215) -- Vec2 "Size"

    function Script:Start()
        self.shader = Shader:Load("HUD Elements/rotate attempt/weird.shader")
        self.intex = Texture:Load("Materials/Developer/bluegrid.tex")
        self.mask= Texture:Load("Materials/Developer/Flat Black.tex")
        self.angle=0
    end

    function Script:UpdateWorld()
        self.angle = Time:GetCurrent()/1000
    end

    function Script:PostRender(context)

        local a = self.a
        local x = self.pos.x
        local y = self.pos.y
        local w = self.size.x
        local h = self.size.y
     
        shd = context:GetShader()
        
        self.intex:Bind(1)

        self.shader:SetFloat("t", -1.0)
        self.shader:SetFloat("angle", self.angle)

        context:SetBlendMode(1)
        context:SetColor(1,1,1,1)
        context:SetShader(self.shader)
        context:DrawImage(self.mask, x, y , w, h)

        context:SetShader(shd)
    end


    ------------------------------------------------------------------------------
    Fragment of shader:

    #version 400
    uniform vec4 drawcolor;
    uniform sampler2D texture0;
    uniform sampler2D texture1;
    uniform float t;

    in vec2 vTexCoords0;
    in vec2 vTexCoords1;

    out vec4 fragData0;

    void main(void)
    {    
        vec4 mask=texture(texture0,vTexCoords0);
        if (mask.r < 0.1 && mask.a > 0.0) {
            vec4 t0 = texture(texture0, vTexCoords0);
            vec4 t1 = texture(texture1, vTexCoords1);
            mask = mix(t0, t1, vec4(vTexCoords1.x >= t));
        }
        else {
            discard;
        }
        fragData0 = mask;
    }


    ------------------------------------------------------------------------------

    Vertex of shader:

    #version 400

    uniform mat4 projectionmatrix;
    uniform mat4 drawmatrix;
    uniform vec2 position[5];
    uniform vec2 texcoords[4];

    uniform float angle = 0.0;


    out vec2 vTexCoords0;
    out vec2 vTexCoords1;


    void main(void)
    {
        float s = sin(angle);
        float c = cos(angle);
     
        mat2 RotationMatrix = mat2(c,-s,s,c);
        
        vec2 pos = position[gl_VertexID];

        gl_Position = projectionmatrix * (drawmatrix * vec4(pos, 0.0, 1.0));
        vTexCoords0 = texcoords[gl_VertexID];
        vTexCoords1 = (texcoords[gl_VertexID] - vec2(0.5, 0.5)) * RotationMatrix + vec2(0.5, 0.5);;
    }

     

    • Like 1
  2. Since the time I asked this question I made a little progress. I have it rotating now using the vertex, but I can't get it to rotate from the center. It centers at the top-left. Here it is:

    Fragment:

    #version 400
    uniform vec4 drawcolor;
    uniform sampler2D texture0;
    uniform sampler2D texture1;
    uniform float t; // e.g. 0.4

    in vec2 vTexCoords0;
    in vec2 vTexCoords1;

    out vec4 fragData0;

    void main(void)
    {    
        vec4 mask=texture(texture0,vTexCoords1);
        if (mask.r < 0.1 && mask.a > 0.0) {
            vec4 t0 = texture(texture0, vTexCoords1);
            vec4 t1 = texture(texture1, vTexCoords0);
            mask = mix(t0, t1, vec4(vTexCoords1.x >= t));
        }
        else {
            discard;
        }
        fragData0 = mask;
    }

     

    Vertex:

    #version 400

    uniform mat4 projectionmatrix;
    uniform mat4 drawmatrix;
    uniform vec2 position[4];
    uniform vec2 texcoords[4];

    uniform float turn = 0.0;

    in vec3 vertex_position;
    in vec2 vertex_texcoords0;

    out vec2 vTexCoords0;
    out vec2 vTexCoords1;

    void main(void)
    {
        vec2 pos = position[gl_VertexID];
        mat2 rot = mat2( cos( radians(turn)), -sin( radians(turn)), sin( radians(turn)),  cos(radians(turn)));

        gl_Position = projectionmatrix * (drawmatrix * vec4(pos, 0.0, 1.0));
        vTexCoords1 = texcoords[gl_VertexID];
        vTexCoords0 = texcoords[gl_VertexID] * rot;
    }

     

     

  3. I have a shader that allows me to move a texture1 within the masked space of a texture0 but I'm only able to move it in a line. I need it to rotate. How can I do that? Here's the fragment shader:

    #version 400
    uniform vec4 drawcolor;
    uniform sampler2D texture0;
    uniform sampler2D texture1;
    uniform float t;    // e.g. 0.4
    uniform vec2 bar = vec2(1.0,1.0);
    uniform bool isbackbuffer;

    in vec2 vTexCoords0;

    out vec4 fragData0;

    void main(void)
    {    
        vec2 UV = (bar);
        if (isbackbuffer) UV.xy = 1.0 - UV.xy;
        vec4 mask=texture(texture0,vTexCoords0);
        if (mask.r < 0.1 && mask.a >0) {
            vec4 t0 = texture(texture0, vTexCoords0);
            vec4 t1 = texture(texture1, vTexCoords0+UV);
            mask = mix(t0, t1, vec4(vTexCoords0.x >= t));
        }
        else {
            discard;
        }
        fragData0 = mask;
    }

        //vec2 turn = vec2(-(cos(2)*(UV.x/2) - sin(2)*(UV.y/2)),(-sin(2)*(UV.x/2) - cos(2)*(UV.y/2)));

     

  4. I have this rotating thing I want to make a health half-circle but I need to mask half of it. How can I do it? Anyone come across a shader for that? Or can it be done in lua? I looked around but I haven't been able to find one that works for this.

    Here's my code, if that's useful:

    Script.player = nil -- entity "Player"
    Script.pos = Vec2(242,234) -- Vec2 "Position"
    Script.offset = Vec2(4,3) -- Vec2 "Offset"
    Script.csize = Vec2(200,200) -- Vec2  "Size"

    function Script:Start()
        self.player = self.entity:GetParent()
        self.tex = Texture:Load("Materials/Developer/bluegrid.tex")
    end

    function Script:PostRender(context)
        local a = Time:GetCurrent() /10
        local w = self.csize.x
        local h = self.csize.y
        local x = self.pos.x-(Math:Cos(a)*(w/2) - Math:Sin(a)*(h/2))
        local y = self.pos.y+(-Math:Sin(a)*(w/2) - Math:Cos(a)*(h/2))
        local scale = 1
        
        context:SetRotation(a)
        context:SetScale(1,1)   
            
        context:SetBlendMode(Blend.Alpha)
        context:SetColor(1,1,1,1)
        context:DrawImage(self.tex, x, y, self.csize.x, self.csize.y)
        context:SetRotation(0)
    end

     

  5. Nope. I got the square moving all over the screen but it won't turn. Here's my script:

    Script.pos = Vec2(242,234) -- Vec2 "Position"
    Script.offset = Vec2(4,3) -- Vec2 "Offset"
    Script.csize = Vec2(200,200) -- Vec2  "Size"
    Script.square = Texture:Load("Materials/Developer/bluegrid.tex")

    function Script:PostRender(context)
        Time:Update()
            
        local a = Time:GetCurrent()*0.1
       
        local x = self.pos.x
        local y = self.pos.y
        local w = self.csize.x
        local h = self.csize.y
            
        local scale = 1
        
        --context:SetRotation(a)
        context:SetScale(scale,scale)   
            
        context:SetBlendMode(Blend.Alpha)
        context:SetColor(1,1,1)
        context:DrawText(text,x,y)
        context:DrawImage(self.square, x-(Math:Cos(a)*(w) - Math:Sin(a)*(h)), y+(-Math:Sin(a)*(w) - Math:Cos(a)*(h)) , self.csize.x, self.csize.y)
        context:SetBlendMode(Blend.Solid)
    end

  6. Here's spectator.lua if you need it:

    Script.movespeed=5.0--float "Move speed"
    Script.movementsmoothing = 0.3--float "Move smoothness"
    Script.radius = 0.5--float "Radius"
    Script.lookspeed = 0.1--float "Look speed"
    Script.looksmoothing = 0.5--float "Look smoothness"

    function Script:Start()
        local window = Window:GetCurrent()
        self.mousepos = window:GetMousePosition()
        self.camerarotation = self.entity:GetRotation()
        if (self.entity:GetMass()==0) then
            self.entity:SetMass(10)
        end
        self.entity:SetGravityMode(false)
        self.entity:SetBuoyancyMode(false)
        self.entity:SetCollisionType(Collision.Projectile)
        if self.entity:GetShape()==nil then
            local shape = Shape:Sphere(0,0,0, 0,0,0, self.radius*2,self.radius*2,self.radius*2)
            self.entity:SetShape(shape)
            shape:Release()
        end
        self.entity:SetFriction(0,0)
        self.entity:SetElasticity(0)
        self.entity:SetSweptCollisionMode(true)
        self.listener = Listener:Create(self.entity)
        self.entity:SetBuoyancyMode(false)
    end

    --Collision filter so the spectator doesn't knock things over
    function Script:Overlap(entity)
        if entity:GetMass()==0 then
            return Collision.Collide
        else
            return Collision.None
        end
    end

    function Script:UpdateWorld()
        local window = Window:GetCurrent()
        local cx = Math:Round(context:GetWidth()/2)
        local cy = Math:Round(context:GetHeight()/2)
        local mpos = window:GetMousePosition()
        window:SetMousePosition(cx,cy)
        local centerpos = window:GetMousePosition()
        if self.started then
            mpos = mpos * self.looksmoothing + self.mousepos * (1-self.looksmoothing)
            local dx = (mpos.x - centerpos.x) * self.lookspeed
            local dy = (mpos.y - centerpos.y) * self.lookspeed        
            self.camerarotation.x = self.camerarotation.x + dy
            self.camerarotation.y = self.camerarotation.y + dx
            self.mousepos = mpos
        else
            self.mousepos = Vec3(centerpos.x,centerpos.y,0)
            self.started=true
        end
    end

    function Script:UpdatePhysics()
        local move=0
        local strafe=0
        local ascension=0
        local window = Window:GetCurrent()
        if window:KeyDown(Key.W) or window:KeyDown(Key.Up) then move = move + self.movespeed end
        if window:KeyDown(Key.S) or window:KeyDown(Key.Down) then move = move - self.movespeed end
        if window:KeyDown(Key.D) or window:KeyDown(Key.Right) then strafe = strafe + self.movespeed end
        if window:KeyDown(Key.A) or window:KeyDown(Key.Left) then strafe = strafe - self.movespeed end
        if window:KeyDown(Key.Q) or window:KeyDown(Key.PageDown) then ascension = ascension - self.movespeed end
        if window:KeyDown(Key.E) or window:KeyDown(Key.PageUp) then ascension = ascension + self.movespeed end
        local currentvelocity = self.entity:GetVelocity(false)
        local desiredvelocity = Vec3(strafe,0,move) + Transform:Vector(0,ascension,0,nil,self.entity)
        local velocity = currentvelocity * self.movementsmoothing + desiredvelocity * (1.0-self.movementsmoothing)
        self.entity:AddForce((desiredvelocity - currentvelocity) * self.entity:GetMass() / self.movementsmoothing,false)
        self.entity:PhysicsSetRotation(self.camerarotation.x,self.camerarotation.y,self.camerarotation.z)
    end

  7. Well so I was able to create a script that I can child to the head and drag in the top parent as an entity. I like this because I don't have to do anything to other scripts. It works but the only problem is when I set the material to Invisible.mat I get no bullet wound texture when shooting the head. The invisible texture hides that, too. Is there an easy way to fix that in this script? I can live without it but it irks me a bit.

    Here's the script:

    Script.parent= "" --entity "Parent"
    Script.size = Vec3(0.30,0.34,0.34) -- Vec3 "Size"
    Script.pos = Vec3(0,0.1,-0.07) -- Vec3 "Offset"
    Script.damageMulti = 10 -- int "Damage Multiplier"

    function Script:Start()

        self.head = self.entity:GetParent()
        self.health = self.parent.script.health

        self.box = Model:Sphere(8)
        self.box:SetScale(self.size)
        self.box:SetKeyValue(self.parent:GetKeyValue("type"))
        self.box:SetPosition(self.head:GetPosition(true))
        self.box:SetParent(self.entity,true)
        self.box:SetPickMode(self.parent:GetPickMode())
        self.box:Translate(self.pos)
        self.box:SetShadowMode(0)

        self.material = Material:Load("Materials/Effects/Invisible.mat")
        self.box:SetMaterial(self.material)

    end

    function Script:Hurt(damage,distributorOfPain)
        if self.health>0 then
            self.health = self.health - (damage * self.damageMulti)
            self.parent.script.health = self.parent.script.health - damage * self.damageMulti
            if self.health<=0 then
                self.health = 0
                self.parent.script.health = Math:Clamp(self.parent.script.health, 0, self.health)
                self.parent.script:SetMode("dying")
                self.box:Hide()
            end
        end
        return
    end

     

    demo.png

  8. Oh yeah in the gun code. This one?

    function Script:FindScriptedParent(entity,func)
        while entity~=nil do
            if entity.script then
                if type(entity.script[func])=="function" then
                    --if entity.script.enabled~=false then
                        return entity
                    --else
                    --    return nil
                    --end
                end
            end
            entity = entity:GetParent()
        end
        return nil
    end

  9. Ok sorry I'm lost already. The pick position? Pass the pick and the Hurt() into the Headshot Box script? Actually that part makes sense but where is the pickposition? Are the entity children a table somewhere that I can iterate them? How do I find the exact limb? It's not as simple as:

    Hurt()...

    if self.headshotBox then

    damage = 100

    end

     

    I can see I should have thought this through longer.

  10. I tried making a hitbox like from your video, but in your video it's just one box and I can't make a distinction in damage on the limbs. I presume there is something I'm missing or did wrong, but I couldn't get that to work. In the AI script I referenced it in the Start() as:

    self.headshotBox=self.entity:FindChild("Headshot Box")

    I made a pivot and attached it to the head limb and attached a script that created a box there:

    function Script:Start()
        self.head = self.entity:GetParent()
        material = Material:Load("HUD Elements/Materials/_original.mat")

        self.box = Model:Box(0.35,0.35,0.35)
        self.box:SetMaterial(material)
        self.box:SetPosition(self.head:GetPosition(true))
        self.box:SetParent(self.head,true)
        self.box:Translate(1,0,0)
    end

     

    The box works like this and reduces health with damage but now I don't know how to reference it. I'm assuming I could do something like in the AI script under the Hurt() function add an "if" statement but what? "If target? == self.headshotBox then...?"

    Or should I add some kind of Hurt() function to the box itself?

     

     

  11. What's the best way to approach headshots? I tried messing with the AI script in the Hurt() function. I tried making a script that created a box around the head. I tried making a pick...seems like the best way would be to add an "if" statement in the AI script Hurt(damage) function by declaring the head but how?

  12. Ok so I added this line in the HUD AI under ChooseTarget():


     if d < self.sightradius then


    ..so it looks like this:

    function Script:ChooseTarget()
        local entities = GetEntityNeighbors(self.entity,self.sightradius,true)
        local k,entity
        for k,entity in pairs(entities) do
            if entity.script.teamid~=nil and entity.script.teamid~=0 and entity.script.teamid~=self.teamid then
                if entity.script.health>0 then
                    local d = self.entity:GetDistance(entity)
                    local pickinfo=PickInfo()
                    if self.entity.world:Pick(self.entity:GetPosition()+Vec3(0,1.6,0),entity:GetPosition()+Vec3(0,1.6,0),pickinfo,0,false,Collision.LineOfSight)==false then
                        if d < self.sightradius then --added so they don't charge from any distance
                        return entity.script
                        end
                    end
                end
            end
        end
    end

     

    Not sure why that's not in the original script. So to OP just what Macklebee suggested above, plus change this one line in your HUD AI script, save it as a prefab if you're spawning them, and also I have to change this line in the minimap script from a 1 to a 2 for the dots to appear:

    local AABB = self.miniMapSphere:GetAABB(1)

    ...so it looks like:
    local AABB = self.miniMapSphere:GetAABB(2)

  13. Yeah that works. The sightrange is still off. I have to set it to -22 to walk up to the crawler. Should be at 0. Is there a way to compensate for that in the minimap script? Like add something to the table?

  14. Thanks for the reply. I just tried your code here. Same problem. Not sure why but it's not working for me with the standard Leadwerks Main.lua. The only format that shows up is:

    context:DrawText("Ammo: "..clip.. " | " ..Ammo, 20,108)

     

    If I use Luawerks instead it works fine, they all show up. So if you have bought Luawerks you can switch the Main.lua back and forth and see. That's the best replication I have right now. I presumed someone would have encountered this and I know a lot of you guys can just troubleshoot these things in your head. Not sure what it is about the Luawerks system that makes it work that is missing in the original.

    Here's one of my scripts where the text isn't showing up in case you want to see if I'm doing something wrong:

    Script.overlayPath = "" --path "Texture" "Tex file (*tex):tex"
    Script.timeBarColor = Vec4(255,128,0,255) --color "Timebar Color"
    Script.fontColor = Vec4(1,1,1,0.8) -- color "Font Color"
    Script.maxTime = 150 --int "Countdown Time"
    Script.radius = 35 --int "Radius"
    Script.cirPos = Vec2(100,180) --Vec2 "Circle Position"

    function Script:Start()

        self.font = Font:Load("Fonts/arialbd.ttf", 10)

        self.player = self.entity:GetParent()
        self.camera = self.player.script.camera

        self.endtime = 0
        self.timer = self.maxTime

        if self.overlayPath ~= "" then
            self.overlay = Texture:Load(self.overlayPath)
        end
    end

    function Script:UpdateWorld()
        self.timer = self.timer - Time:GetSpeed()/100
        if     self.timer < self.endtime then
            self.timer = 0
            self:GameOver()
        end
    end

    function Script:GameOver()
        self.player.script.health = 0
        self.player.script:Kill()
        self.entity:Release()
    end

    function Script:PostRender(context)

        local x = 0
        local y = 0
        local r = self.radius
        local G = 1000
        local countdown = self.timer/self.maxTime
        local p = self.radius + self.radius/5

        w = context:GetWidth()/context:GetWidth() + self.cirPos.x
        h = context:GetHeight()/2 + self.cirPos.y

        context:SetBlendMode(1)
        
        --draw overlay
        if self.overlayPath ~= nil then
            context:SetColor(1,1,1,0.45)
            context:DrawImage(self.overlay, w-p, h-p, p*2, p*2)
        end

        -- draw circle
        for k = 0, G do
            a = 360 / G * k *(countdown)

            X = -(r * Math:Sin(a)) + x
            Y = -(r * Math:Cos(a)) + y

            context:SetColor(self.timeBarColor)
            context:DrawRect(X + w, Y + h, X/5 , Y/5, 1)
        end

        --draw text
        context:SetColor(self.fontColor)
        context:SetFont(self.font)
        context:DrawText(string.format("%.0f",self.timer), w-14, h-14, 30, 30, Text.VCenter+Text.Center)
    end

  15. It appears this format shows up on start:

        context:DrawText("Ammo: "..clip.. " | " ..Ammo, 20,108)

    ...but this does not:

        context:DrawText(string.format("Ammo: "..clip.. " | " ..Ammo), 20, 108, 100, 30, Text.VCenter+Text.Center)



    It works fine with ReepBlue's Luawerks so perhaps there's something missing in the Leadwerks Main.lua or Menu.lua which accounts for this? I just don't know where to look.

     

     

×
×
  • Create New...