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.

Fading Spectre

Postby Boondorl » Mon Jan 07, 2019 3:38 am

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
Boondorl
 
Joined: 11 Jul 2018

Re: Fading Spectre

Postby Apeirogon » Mon Jan 07, 2019 9:43 am

You can check distance to player actor using distance2d/3d function, to change decide on what value script must change transparency of spectre.
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Fading Spectre

Postby Boondorl » Mon Jan 07, 2019 2:36 pm

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
Boondorl
 
Joined: 11 Jul 2018

Re: Fading Spectre

Postby Apeirogon » Mon Jan 07, 2019 4:28 pm

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.
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Fading Spectre

Postby phantombeta » Mon Jan 07, 2019 4:39 pm

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.
Last edited by phantombeta on Mon Jan 07, 2019 4:55 pm, edited 1 time in total.
User avatar
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: phantombeta_
Github ID: Doom2fan
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

Re: Fading Spectre

Postby Apeirogon » Mon Jan 07, 2019 4:49 pm

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?!
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Fading Spectre

Postby phantombeta » Mon Jan 07, 2019 4:53 pm

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
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: phantombeta_
Github ID: Doom2fan
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

Re: Fading Spectre

Postby Boondorl » Mon Jan 07, 2019 7:35 pm

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
Boondorl
 
Joined: 11 Jul 2018

Re: Fading Spectre

Postby Nash » Tue Jan 08, 2019 1:17 am

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
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: Fading Spectre

Postby Boondorl » Tue Jan 08, 2019 1:46 am

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.
User avatar
Boondorl
 
Joined: 11 Jul 2018


Return to Scripting

Who is online

Users browsing this forum: No registered users and 3 guests

cron