[Solved] SKYBOX viewpoint move in relation to the player?

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!)
User avatar
Tormentor667
Posts: 13554
Joined: Wed Jul 16, 2003 3:52 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia (Modern GZDoom)
Location: Germany

[Solved] SKYBOX viewpoint move in relation to the player?

Post by Tormentor667 »

I know, I can remember that I have asked this already times before but I can't find the appropriate thread or solution anymore. So here is what I have:

Imagine having a large outdoor area, in which the player is moving. This area also uses a skybox, which is smaller than the outdoor area. Now normally, the skybox viewpoint would stick where it is and not move when you travel through the outdoor area. But what can I do to make the skybox viewpoint seamlessly move according to the player speed and direction, just much slower (a fractional definable part) so it looks like the skybox is part of the area where the sky is used in?

Thanks already for your support
Last edited by Tormentor667 on Sun Dec 24, 2017 2:02 pm, edited 1 time in total.
User avatar
Rachael
Posts: 13885
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: Making a SKYBOX viewpoint move in relation to the player

Post by Rachael »

This has not been implemented yet. I was actually going to implement this willy nilly at one point, but the code relating to skyboxes is really complicated right now.
User avatar
Tormentor667
Posts: 13554
Joined: Wed Jul 16, 2003 3:52 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia (Modern GZDoom)
Location: Germany

Re: Making a SKYBOX viewpoint move in relation to the player

Post by Tormentor667 »

Could it be done somehow through ACS?
User avatar
Rachael
Posts: 13885
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: Making a SKYBOX viewpoint move in relation to the player

Post by Rachael »

If it can, it definitely won't be smooth.

I think your best bet might be to try it through ZScript, since ZScript can call the SkyboxCam object directly without a tag and can be run during intertics.
User avatar
AFADoomer
Posts: 1339
Joined: Tue Jul 15, 2003 4:18 pm

Re: Making a SKYBOX viewpoint move in relation to the player

Post by AFADoomer »

Here's an initial hack at doing this in ZScript... This actor can be used in place of a standard SkyViewpoint actor. Argument 1 controls the amount of scaling of the viewpoint's movement.

Code: Select all

class SkyViewPointStatic : SkyViewPoint
{
    PlayerPawn base;
    Vector3 basepos;
    int scaling;

    Default
    {
        //$Arg1 "Skybox Scene Scale"
        //$Arg1Tooltip "The scale of the skybox's scene (default is 100).  The larger this number is, the farther away the skybox contents will appear to be."
    }

    override void PostBeginPlay()
    {
        // Set the scaling value according to whatever arg 1 value is passed; use 100 if nothing provided
        scaling = args[1] == 0 ? 100 : args[1];

        // Save the spawn location vector for later
        SpawnPoint = pos;

        // Iterate through all of the possible players in the game
        for (int i = 0; i < MAXPLAYERS; i++)
        {
            // If a player is in the game and has spawned...
            if (playeringame[i] && players[i].mo)
            {
                if (!base) { base = players[i].mo; } // Set the skybox to follow the first player who is in the game
                else { base = null; break; } // If there are multiple players, don't move the skybox
            }
        }
    }

    override void Tick()
    {
        if (base)
        {
            Vector3 newvel;

            // Reset the viewpoint's height location
            double heightdelta = (base.pos.z - base.floorz) / scaling;
            SetOrigin((pos.x, pos.y, SpawnPoint.z + heightdelta), true);

            // Only move the viewpoint on the x/y axis if the player actually is moving along that axis; otherwise stay still
            if (basepos.x != base.pos.x) { newvel.x = base.vel.x; }
            if (basepos.y != base.pos.y) { newvel.y = base.vel.y; }
            newvel.z = -base.vel.z;

            // Adjust the move amount by scaling value
            newvel /= scaling;
            A_ChangeVelocity(newvel.x, newvel.y, newvel.z, CVF_RELATIVE | CVF_REPLACE);

            // Save the player's old position for the move checks
            basepos = base.pos;
        }

        Super.Tick();
    }
}
Probably not perfect, but it works...

EDIT: Updated with fixed code that doesn't botch the rotational math.
Last edited by AFADoomer on Sun Dec 24, 2017 9:51 am, edited 1 time in total.
User avatar
Ozymandias81
Posts: 2067
Joined: Thu Jul 04, 2013 8:01 am
Graphics Processor: nVidia with Vulkan support
Location: Mount Olympus, Mars

Re: Making a SKYBOX viewpoint move in relation to the player

Post by Ozymandias81 »

Maybe this try could be of help, still didn't test btw
User avatar
ibm5155
Posts: 1268
Joined: Wed Jul 20, 2011 4:24 pm

Re: Making a SKYBOX viewpoint move in relation to the player

Post by ibm5155 »

I did a moving sky in Glitchland
In case you want, I did a loop calling this line

Code: Select all

script 2 ENTER{
    int H = 20;
    int A = 50;
    thing_changetid(playernumber(),playernumber()+1000);
    while(true){ 
 >>>>>    SetActorPosition(2, -GetActory(1000)/100+14096.0, GetActorX(1000)/100+19424.0, GetActorZ(1000)/25+48.0, 0);
        if(H>0){
            if(GetActorProperty(0,APROP_Health) < 20){
                H--;
                SpawnForced("Stimpack",getactorx(1000),getactory(1000),getsectorceilingz(0,getactorx(1000),getactory(1000))-10.0,0,0);
                delay(35*10);
            }
        }
        if(A>0){
            if(CheckWeapon("Pistol") || CheckWeapon("Chaingun")){
               if(CheckInventory("Clip") < 3){
                    A--;
                    SpawnForced("Clip",getactorx(1000),getactory(1000),getsectorceilingz(0,getactorx(1000),getactory(1000))-10.0,0,0);
                    delay(35*10);
                }
            }
            if(CheckWeapon("Shotgun") || CheckWeapon("SuperShotgun")){
                if(CheckInventory("Shell") < 3){
                    A--;
                    SpawnForced("Shell",getactorx(1000),getactory(1000),getsectorceilingz(0,getactorx(1000),getactory(1000))-10.0,0,0);
                    delay(35*10);
                }
            }
        }
        
        delay(1);
    }
}
EDIT: The only draw side is that it's single player only (maybe with zandronum using clientside scripts)
User avatar
Tormentor667
Posts: 13554
Joined: Wed Jul 16, 2003 3:52 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia (Modern GZDoom)
Location: Germany

Re: Making a SKYBOX viewpoint move in relation to the player

Post by Tormentor667 »

Can confirm: AFADoomers code works like a charm, thanks kindly :)
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: [Solved] SKYBOX viewpoint move in relation to the player

Post by ZZYZX »

I suggest using players.camera, not players.mo, because player sometimes F12's or does other complex things.
Sadly I personally don't know how to detect chasecam (other than &CF_CHASECAM and duplicate logic, but that's not really a good way to do it)

Obligatory notice that if someone (looks at Graf and Eruanna, especally Eruanna) didn't block my RenderFrame code, we'd be able to change skybox depending on which view is currently rendering. Transparently supporting all kinds of weird camera hacks that GZDoom has — security cameras, preview security cameras (cameratextures), skyboxes, portals, line portals, chasecams, etc...

Note: there is still RenderOverlay event that has this:

Code: Select all

struct RenderEvent native ui version("2.4")
{
    native readonly Vector3 ViewPos;
    native readonly double ViewAngle;
    native readonly double ViewPitch;
    native readonly double ViewRoll;
    native readonly double FracTic;
    native readonly Actor Camera;
}
You can probably pick up real camera pos from there, but high chance that it won't work (I'm not sure if ViewPos and everything else gets saved before it goes into portals/skyboxes, it might NOT, as such this event will receive "last used" data and not the one you see...)
User avatar
AFADoomer
Posts: 1339
Joined: Tue Jul 15, 2003 4:18 pm

Re: [Solved] SKYBOX viewpoint move in relation to the player

Post by AFADoomer »

Yeah, there are a few quirks with just using player position... Bob isn't accounted for, and I need to tweak how I'm accounting for height changes.

I think it's "good enough" for right now, but I'll experiment with using the camera (and possible the RenderEvent) and see if that produces better results.

Thanks!
User avatar
Zeberpal
Posts: 191
Joined: Sun Apr 28, 2013 2:06 am
Location: RU

Re: [Solved] SKYBOX viewpoint move in relation to the player

Post by Zeberpal »

Hello! Thank you for this kind of script!
If it is okay to post a little cry for help here: I have never touched ZSCRIPT before, but I'm dying to implement this feature in my map.

I wish you could spare a few bits to explain how to import this script into PK3 and ultimately make it work in GZDoom.

Here is what I do:
1) Create zscript.zsc file and copypaste AKADoomer's code. There is nothing more than that in my .Pk3
2) :? Since it seems to be a replacement for SkyboxViewpoint, I put it(thing type 9080) in my map, play with Argument 1 as it requires, however nothing happens.

How to do it right?
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: [Solved] SKYBOX viewpoint move in relation to the player

Post by ramon.dexter »

Zeberpal: your assumption is not correct. The new skypoint inherits from skyboxviewpoint, but nothing more. You need to assign it a doomed number in order to work with it.

Check this: https://zdoom.org/wiki/Using_inheritance
User avatar
Zeberpal
Posts: 191
Joined: Sun Apr 28, 2013 2:06 am
Location: RU

Re: [Solved] SKYBOX viewpoint move in relation to the player

Post by Zeberpal »

ramon.dexter wrote:You need to assign it a doomed number in order to work with it.
Thanks for reply ramon.dexter, it works now) However, it seems it is impossible to give a number to a class like we do in DECORATE?
So I used MAPINFO to assign DoomEdNums there

Code: Select all

DoomEdNums
{
666 = SkyViewPointStatic, 0, 11, 0, 0, 0  //AFADoomer's class
}
Wondering if it is an okay practice.
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: [Solved] SKYBOX viewpoint move in relation to the player

Post by ramon.dexter »

zeberpal: No, you cannot assign doomed number to the in the way like in decorate (actor blabla 12345). But the assignement in mapinfo is similar. It is assigned to the one class (also, you need only the number; whats behind it is not neccessary.

Return to “Scripting”