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.

Better gravity projectile launching?

Postby Major Cooke » Thu Feb 15, 2018 7:55 am

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
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: Better gravity projectile launching?

Postby Matt » Thu Feb 15, 2018 10:48 am

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

Code: Select allExpand view
    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
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Better gravity projectile launching?

Postby Major Cooke » Wed Feb 21, 2018 5:45 pm

This is called just once, right before actually doing A_SpawnProjectile for example, right?
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: Better gravity projectile launching?

Postby Matt » Thu Feb 22, 2018 2:16 pm

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
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: Better gravity projectile launching?

Postby Major Cooke » Thu Mar 01, 2018 11:05 am

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
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: Better gravity projectile launching?

Postby Matt » Thu Mar 01, 2018 12:38 pm

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.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia


Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest