Problem with toggling transparency on sprite objects

Titou

Member
So what I want to do is making a code that makes objects transparent when they are too far from the player.

I have this as a base but it doesn't work, I have attempted various ways, but none of them work...

Lua:
addHook("MobjThinker", function(mobj)
    local dist = R_PointToDist2(players[0].mo.x, players[0].mo.y, mobj.x, mobj.y)/FRACUNIT
            
    if dist < 2000 and mobj.frame == FF_TRANS70
        mobj.frame = $ - FF_TRANS70
    elseif dist >= 2000 and mobj.frame != FF_TRANS70
        mobj.frame = FF_TRANS70|$
    end
end)

and what I get (as my best result?):

kart0071.gif


I'm pretty much missing the logic, I'm not sure if my base is correct or not (I did tested with MF2_DONTDRAW before and it works apparently), so if someone could help me understand this, that would be nice! I pretty much want to get better at coding for other projects.
 
To check if the frame has FF_TRANS70, use "mobj.frame & FF_TRANS70" instead of "mobj.frame == FF_TRANS70" (Similarly, add a "not" to the start to see if it DOESN'T have it). As it is, I'm assuming the equality check only works for the first frame, since A|FF_TRANS70 is the same thing as FF_TRANS70.
 
Well thanks I guess I'm really the dumbest because I already used this syntax before, I also fixed my problem.
I really didn't read the wiki well despite having 50 tabs whenever I'm coding...
 

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top