Better gravity projectile launching?

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
Major Cooke
Posts: 8176
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Better gravity projectile launching?

Post by Major Cooke »

Replicating the Doom 2016 imp's gravity fireballs is a tad bit more difficult than I thought it would be. I'm trying to properly calculate the throwing distance and how high the projectile needs to be launched in order to hit the target. For right now I'm just pretending there's no obstructions like low ceilings or anything like that, though I will eventually turn my focus to it if possible.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Better gravity projectile launching?

Post by Matt »

It's far from perfect but here's what I've been doing with the marines' grenade launchers in HD:

Code: Select all

    void A_DropAdjust(class<actor> missiletype,double dist=0,bool userocket=false){
        double dist=max(1,(target?distance2d(target):0));
        double spd=getdefaultbytype(missiletype).speed;
        if(getdefaultbytype(missiletype).gravity&&dist>spd){
            if(userocket&&missiletype is "GyroGrenade")spd*=6.4; //used only for the gyrorockets
            int ticstotake=dist/spd;
            int dropamt=0;
            for(int i=1;i<=ticstotake;i++){
                dropamt+=i;
            }
            pitch-=min(atan(dropamt/dist),30);
        }

        //because we don't shoot from height 32 but 42
        if(dist>0)pitch+=atan(10/dist);
    }
(That cap on the pitch change should probably be omitted along with the additional adjustment for shooting height)

EDIT: Dropamt should also be multiplied by the projectile's actual gravity - I've gotten away with assuming 1 for everything since that's all that the HD marines will ever shoot.
User avatar
Major Cooke
Posts: 8176
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Better gravity projectile launching?

Post by Major Cooke »

This is called just once, right before actually doing A_SpawnProjectile for example, right?
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Better gravity projectile launching?

Post by Matt »

Yeah.

You could change the last line to have it return a pitch value instead of directly changing the caller's pitch if you want to do more adjustments (or you need the shooter facing a different pitch for whatever reason).
User avatar
Major Cooke
Posts: 8176
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Better gravity projectile launching?

Post by Major Cooke »

Hmm, do you think this could also apply to monster leaping?

Bearing in mind I may also need to slow down the speed based on distance... not quite sure what I should do there.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Better gravity projectile launching?

Post by Matt »

I see no reason why it would not! (and thanks for the reminder too...)

The angle calculation should work at any distance for the same speed (and at least the same elevation), though the leaping monster might think it's a good idea not to leap as hard in case it misses and overshoots. I would have it determine the ideal speed and save that variable somewhere to be called in the drop compensation function.
Post Reply

Return to “Scripting”