Fading Spectre

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Boondorl
Posts: 137
Joined: Wed Jul 11, 2018 10:57 pm

Fading Spectre

Post 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?
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Fading Spectre

Post 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.
User avatar
Boondorl
Posts: 137
Joined: Wed Jul 11, 2018 10:57 pm

Re: Fading Spectre

Post 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.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Fading Spectre

Post 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.
User avatar
phantombeta
Posts: 2084
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Fading Spectre

Post by phantombeta »

That's wrong, actually. You can set the alpha based on the distance to the consoleplayer quite easily.

Code: Select all

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.
Last edited by phantombeta on Mon Jan 07, 2019 3:55 pm, edited 1 time in total.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Fading Spectre

Post 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?!
User avatar
phantombeta
Posts: 2084
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Fading Spectre

Post 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.
User avatar
Boondorl
Posts: 137
Joined: Wed Jul 11, 2018 10:57 pm

Re: Fading Spectre

Post 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:
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: Fading Spectre

Post 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.
User avatar
Boondorl
Posts: 137
Joined: Wed Jul 11, 2018 10:57 pm

Re: Fading Spectre

Post 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.
Post Reply

Return to “Scripting”