Better gravity projectile launching?
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!)
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!)
-
- Posts: 8205
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Windows 10
- Graphics Processor: nVidia with Vulkan support
- Location: GZBoomer Town
Better gravity projectile launching?
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.
-
- 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
Re: Better gravity projectile launching?
It's far from perfect but here's what I've been doing with the marines' grenade launchers in HD:
(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.
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);
}
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.
-
- Posts: 8205
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Windows 10
- Graphics Processor: nVidia with Vulkan support
- Location: GZBoomer Town
Re: Better gravity projectile launching?
This is called just once, right before actually doing A_SpawnProjectile for example, right?
-
- 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
Re: Better gravity projectile launching?
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).
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).
-
- Posts: 8205
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Windows 10
- Graphics Processor: nVidia with Vulkan support
- Location: GZBoomer Town
Re: Better gravity projectile launching?
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.
Bearing in mind I may also need to slow down the speed based on distance... not quite sure what I should do there.
-
- 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
Re: Better gravity projectile launching?
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.
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.