Page 1 of 1

Fading Spectre

PostPosted: Mon Jan 07, 2019 3:38 am
by Boondorl
Currently I'm rewriting how the Spectre's invisibility works. As it gets further away from its target, it becomes more invisible and vice versa. The issue is that this change in transparency is global so, if next to its target, it'll be fully visible at all ranges, even if it's attacking something other than the player. I want to make it a more localized effect so that a player will only ever see it when close by, regardless of what target the Spectre has. In other words, I need the visibility to be proximity based to any actor as opposed to target based, and it needs to be localized to that actor in close range. Is there a way to do this via ZScript?

Re: Fading Spectre

PostPosted: Mon Jan 07, 2019 9:43 am
by Apeirogon
You can check distance to player actor using distance2d/3d function, to change decide on what value script must change transparency of spectre.

Re: Fading Spectre

PostPosted: Mon Jan 07, 2019 2:36 pm
by Boondorl
Unfortunately it would still be global. Multiplayer isn't too big of a concern, but it does still exist and I'm interested if there's a way to make the Spectre's transparency level localized to only players that are close by instead of everyone in the game.

Re: Fading Spectre

PostPosted: Mon Jan 07, 2019 4:28 pm
by Apeirogon
You can check distance directly to player, if you know how find pointer to it.

And no, it cant be done as localized thing. Renderer "guts" of gzdoom is out of control of modders. Because its a source port, not a standalone game (engine), I think.

Re: Fading Spectre

PostPosted: Mon Jan 07, 2019 4:39 pm
by phantombeta
That's wrong, actually. You can set the alpha based on the distance to the consoleplayer quite easily.
Code: Select allExpand view
class FadingSpectre : Demon {
    default {
        // We HAVE to set the renderstyle here, because GZDoom defaults to "Normal", which ignores alpha.
        RenderStyle "Translucent";
    }

    override void Tick () {
        Super.Tick ();

        // Set the actor's alpha here. We have to subtract the value from 1.
        // to invert it so it gets more visible the closer it is to the player.
        // It also restricts it to 25% alpha minimum so the spectre doesn't become completely invisible
        alpha = clamp (1. - (Distance3D (players [consoleplayer].camera) / 512.), .25, 1.);
    }


You just can't combine it with something like A_FadeOut with the FTF_REMOVE flag, which removes the actor if it reaches 0 alpha, or it can cause desyncs.
(There are ways to combine with such things without desyncs, but it's not something you should do or even attempt if you don't know how GZDoom's internals work in detail)

EDIT: Added a small change to make it work if the player is looking through the "eyes" of another player or actor.

Re: Fading Spectre

PostPosted: Mon Jan 07, 2019 4:49 pm
by Apeirogon
He need change spectre alpha for EVERY player in game, so that player from 1 meter from specter see it fully opaque, while player from 100 see same spectre fully transparent.
Or I understand it wrong?!

Re: Fading Spectre

PostPosted: Mon Jan 07, 2019 4:53 pm
by phantombeta
They want it to be more visible the closer it is to the local player - so no, there's nothing about checking the distance to all players here.

Re: Fading Spectre

PostPosted: Mon Jan 07, 2019 7:35 pm
by Boondorl
Apeirogon wrote:He need change spectre alpha for EVERY player in game, so that player from 1 meter from specter see it fully opaque, while player from 100 see same spectre fully transparent.
Or I understand it wrong?!


That is correct. Finding the distance to any player is easy, but I'm not sure if there's a way to set it so it only changes client-side. I suspect that might be beyond simple modding. :lol:

Re: Fading Spectre

PostPosted: Tue Jan 08, 2019 1:17 am
by Nash
The solution phantombeta posted already does exactly what you wanted - the alpha is affected only for the current consoleplayer, which means you. Other players will not see the effect.

Granted, the REAL way to do this is to make sure only the client-side actor's alpha is affected, but GZDoom does not run on client/server architecture yet, so consoleplayer is the closest you'll get for now.

Re: Fading Spectre

PostPosted: Tue Jan 08, 2019 1:46 am
by Boondorl
Nash wrote:Granted, the REAL way to do this is to make sure only the client-side actor's alpha is affected, but GZDoom does not run on client/server architecture yet, so consoleplayer is the closest you'll get for now.

Ah, this was more along the lines of what I was looking for. Glad to know there's still an easy enough workaround that offers similar functionality.