Is there any hitscan laserbeam-like function that has autoaim?
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: 7
- Joined: Fri Dec 02, 2022 11:49 am
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Overly Customized Windows 10 Pro
Is there any hitscan laserbeam-like function that has autoaim?
I want to find a command that shoots out a hitscan with a beam-like effect just like the Doom 64's Unmaker.
-
-
- Posts: 1822
- Joined: Sun Jul 21, 2019 8:54 am
Re: Is there any hitscan laserbeam-like function that has autoaim?
A_RailAttack might be what you want.
-
- Admin
- Posts: 6191
- Joined: Thu Feb 26, 2004 3:02 pm
- Preferred Pronouns: He/Him
Re: Is there any hitscan laserbeam-like function that has autoaim?
It can also be achieved with some custom scripting, if you want to customize the effect.
In DECORATE, a fairly simple method is to have a normal hitscan attack with a custom bulletpuff. That puff contains a pointer back to the originating actor, so you can draw or spawn a beam "in reverse". This is how bullet tracers for hitscans are commonly done.
In ZScript, the AimLineAttack() function is a generic aimed hitscan attack which likewise returns a bunch of useful data in a struct, such as a pointer to the target object. This data (with some math) can also be used to draw the laser, and is generally a lot more powerful and flexible than DECORATE.
In DECORATE, a fairly simple method is to have a normal hitscan attack with a custom bulletpuff. That puff contains a pointer back to the originating actor, so you can draw or spawn a beam "in reverse". This is how bullet tracers for hitscans are commonly done.
In ZScript, the AimLineAttack() function is a generic aimed hitscan attack which likewise returns a bunch of useful data in a struct, such as a pointer to the target object. This data (with some math) can also be used to draw the laser, and is generally a lot more powerful and flexible than DECORATE.
-
- Posts: 7
- Joined: Fri Dec 02, 2022 11:49 am
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Overly Customized Windows 10 Pro
Re: Is there any hitscan laserbeam-like function that has autoaim?
Jarewill wrote:
> [url=https://zdoom.org/wiki/A_RailAttack]A_RailAttack[/url] might be what
> you want.
How can I make it autoaim?
> [url=https://zdoom.org/wiki/A_RailAttack]A_RailAttack[/url] might be what
> you want.
How can I make it autoaim?
-
- Posts: 7
- Joined: Fri Dec 02, 2022 11:49 am
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Overly Customized Windows 10 Pro
Re: Is there any hitscan laserbeam-like function that has autoaim?
Caligari87 wrote:
> It can also be achieved with some custom scripting, if you want to
> customize the effect.
>
> In DECORATE, a fairly simple method is to have a normal hitscan attack with
> a custom bulletpuff. That puff contains a pointer back to the originating
> actor, so you can draw or spawn a beam "in reverse". This is how
> bullet tracers for hitscans are commonly done.
>
> In ZScript, the AimLineAttack() function is a generic aimed hitscan attack
> which likewise returns a bunch of useful data in a struct, such as a
> pointer to the target object. This data (with some math) can also be used
> to draw the laser, and is generally a lot more powerful and flexible than
> DECORATE.
>
>
Tell me how to do the decorate method.
> It can also be achieved with some custom scripting, if you want to
> customize the effect.
>
> In DECORATE, a fairly simple method is to have a normal hitscan attack with
> a custom bulletpuff. That puff contains a pointer back to the originating
> actor, so you can draw or spawn a beam "in reverse". This is how
> bullet tracers for hitscans are commonly done.
>
> In ZScript, the AimLineAttack() function is a generic aimed hitscan attack
> which likewise returns a bunch of useful data in a struct, such as a
> pointer to the target object. This data (with some math) can also be used
> to draw the laser, and is generally a lot more powerful and flexible than
> DECORATE.
>
>
Tell me how to do the decorate method.
-
- Posts: 1060
- Joined: Sun Feb 25, 2018 2:30 am
- Location: UK
Re: Is there any hitscan laserbeam-like function that has autoaim?
Rails fired by the player don't autoaim. I believe this is due to Skulltag days where the point of the railgun was for an accuracy/sniper weapon, but I could be wrong.
However, I get around it myself in Walpurgis by making the weapon create a spawn point, which in turn uses A_CustomRailgun (the monster version), which can aim, and then kills itself.
Like this:
And then get your weapon to spawn this in it's firing frame:
Possibly spawn it the frame before your actual fire, as doing it this way induces a slight lag. All the sin/cos calculations are not strictly neccessary, but the angle of fire will be off otherwise. Be sure to set whatever sprite the railgun uses for its parts to be friendly if you use them, or else they will kill the player if they intersect them. Also, if there are no other potential targets, the weapon may still target the player sometimes; such is fuss of using a monster-based solution.
The other potential solution is to use a FastProjectile and use its trail function to drop parts of your beam. It'll be a pulse laser rather than a beam, but the effect is similar.
However, I get around it myself in Walpurgis by making the weapon create a spawn point, which in turn uses A_CustomRailgun (the monster version), which can aim, and then kills itself.
Like this:
Code: Select all
Actor HandMarker //This is an invisible target point summoned as the primary fire.
{
var float user_howfar;
+INVISIBLE
+FRIENDLY
+DONTHARMSPECIES
+THRUACTORS
+FORCERADIUSDMG
+NOGRAVITY
+NOTIMEFREEZE
+STANDSTILL
+NOINTERACTION
Projectile
Speed 30
Radius 1
Height 1
Species "PlayerAlly"
DamageType "Electric"
States
{
Spawn:
TNT1 A 0 Nodelay A_JumpIfInventory("ComboCounter",1,"Death")
TNT1 A 0 { A_SetUserVarFloat(user_howfar,GetDistance(true,AAPTR_MASTER));
A_Warp(AAPTR_MASTER,cos(-pitch)*user_howfar,8,34+sin(-pitch)*user_howfar,0,WARPF_NOCHECKPOSITION|WARPF_COPYPITCH|WARPF_COPYVELOCITY);}
TNT1 A 0 A_CustomRailgun((random(12,18)+random(2,4)),0,"0B 3C 9E","0B 3C 9E",RGF_SILENT|RGF_EXPLICITANGLE|RGF_NORANDOMPUFFZ,2,180,"DecorativeZaps",0,0,650,2,0,0,"LaserBall2")
Stop
Death:
TNT1 A 0
Stop
}
}
Code: Select all
A_SpawnItemEx("HandMarker",cos(pitch)*28,12,34-(sin(pitch)*28),cos(pitch)*1,cos(pitch)*velx,0,-sin(pitch)*velz,SXF_NOCHECKPOSITION|SXF_SETMASTER|SXF_TRANSFERPITCH)
The other potential solution is to use a FastProjectile and use its trail function to drop parts of your beam. It'll be a pulse laser rather than a beam, but the effect is similar.
-
- Posts: 7
- Joined: Fri Dec 02, 2022 11:49 am
- Preferred Pronouns: He/Him
- Operating System Version (Optional): Overly Customized Windows 10 Pro
Re: Is there any hitscan laserbeam-like function that has autoaim?
Is there a tutorial for this?Caligari87 wrote: ↑Sun Apr 23, 2023 10:51 am It can also be achieved with some custom scripting, if you want to customize the effect.
In DECORATE, a fairly simple method is to have a normal hitscan attack with a custom bulletpuff. That puff contains a pointer back to the originating actor, so you can draw or spawn a beam "in reverse". This is how bullet tracers for hitscans are commonly done.
In ZScript, the AimLineAttack() function is a generic aimed hitscan attack which likewise returns a bunch of useful data in a struct, such as a pointer to the target object. This data (with some math) can also be used to draw the laser, and is generally a lot more powerful and flexible than DECORATE.
-
- Posts: 8
- Joined: Sun Nov 12, 2023 5:42 am
- Preferred Pronouns: He/Him
Re: Is there any hitscan laserbeam-like function that has autoaim?
There is no wiki page for AimLineAttack. Can someone write one please? Is it like a raycast where it points in one direction and returns info about the first thing that it hits? Or does it scan a range and find an angle to something in that area?
-
-
- Posts: 1822
- Joined: Sun Jul 21, 2019 8:54 am
Re: Is there any hitscan laserbeam-like function that has autoaim?
AimLineAttack is similar to LineTrace with the addition of having autoaim.
While it has no wiki page, you can see it in action in the A_BFGSpray function located in gzdoom.pk3:zscript/actors/doom/weaponbfg.zs
When calling AimLineAttack, it will return a FTranslatedLineTarget pointer that you can use to access what monster was hit.
Here's a cutdown example from the BFG function:
While it has no wiki page, you can see it in action in the A_BFGSpray function located in gzdoom.pk3:zscript/actors/doom/weaponbfg.zs
When calling AimLineAttack, it will return a FTranslatedLineTarget pointer that you can use to access what monster was hit.
Here's a cutdown example from the BFG function:
Code: Select all
FTranslatedLineTarget t; //Save what was hit to this variable
target.AimLineAttack(angle, 1024, t, 32); //Cast a line
if (t.linetarget != null) //If something was hit
{
t.linetarget.DamageMobj(target, target, 10, 'BFGSplash', DMG_USEANGLE, t.angleFromSource); //Damage it
}
-
- Posts: 8
- Joined: Sun Nov 12, 2023 5:42 am
- Preferred Pronouns: He/Him
Re: Is there any hitscan laserbeam-like function that has autoaim?
For AimLineAttack, are you saying that we have to set the horizontal angle, but it should aim vertically toward any shootable actor? If that is the case, then technically A_BFGSpray may miss a few enemies within the angle range if they stand between the rays. But if there are a sufficient number of rays, an enemy standing within range would be unlikely to be missed by one.
-
- Posts: 8
- Joined: Sun Nov 12, 2023 5:42 am
- Preferred Pronouns: He/Him
Re: Is there any hitscan laserbeam-like function that has autoaim?
I am using AimLineAttack from a primary projectile to pick out a target to shoot at during flight. I want to use A_SpawnProjectile to shoot another projectile at it. How can I take the actor returned in the FTranslatedLineTarget (linetarget) and pass it into the target parameter for A_SpawnProjectile? I thought maybe I could assign the tracer pointer to it if I can't pass it in directly.
Other than that, I've tried using angleFromSource to specify the projectile launch angle as an absolute angle (using CMF_AIMDIRECTION), but that produced results that weren't correct for all directions. Using the return double from AimLineAttack does appear to set the correct absolute pitch though. Using angleFromSource to change the facing direction of the primary projectile to make it face the target does appear to work correctly. Is there a way to have A_SpawnProjectile shoot in the direction that the shooter is facing without trying to aim at a target or an absolute direction? This is not ideal though if I am using sprite facing angles for the primary projectile, since I don't want it to always face the thing it's shooting at while it's flying in a different direction.
Other than that, I've tried using angleFromSource to specify the projectile launch angle as an absolute angle (using CMF_AIMDIRECTION), but that produced results that weren't correct for all directions. Using the return double from AimLineAttack does appear to set the correct absolute pitch though. Using angleFromSource to change the facing direction of the primary projectile to make it face the target does appear to work correctly. Is there a way to have A_SpawnProjectile shoot in the direction that the shooter is facing without trying to aim at a target or an absolute direction? This is not ideal though if I am using sprite facing angles for the primary projectile, since I don't want it to always face the thing it's shooting at while it's flying in a different direction.
-
-
- Posts: 1822
- Joined: Sun Jul 21, 2019 8:54 am
Re: Is there any hitscan laserbeam-like function that has autoaim?
Yes indeed.Slayer777 wrote: ↑Sun Nov 12, 2023 7:44 pm For AimLineAttack, are you saying that we have to set the horizontal angle, but it should aim vertically toward any shootable actor? If that is the case, then technically A_BFGSpray may miss a few enemies within the angle range if they stand between the rays. But if there are a sufficient number of rays, an enemy standing within range would be unlikely to be missed by one.
That's also why the BFG calls that function 40 times in a cone.
I recommend using SpawnMissile here:Slayer777 wrote: ↑Mon Nov 13, 2023 1:37 pm I am using AimLineAttack from a primary projectile to pick out a target to shoot at during flight. I want to use A_SpawnProjectile to shoot another projectile at it. How can I take the actor returned in the FTranslatedLineTarget (linetarget) and pass it into the target parameter for A_SpawnProjectile? I thought maybe I could assign the tracer pointer to it if I can't pass it in directly.
SpawnMissile(t.linetarget,"Projectile",target);
First parameter sets the target of the attack, the second one sets what projectile to fire and the third sets who the owner should be. (For example target if you want the projectile to track the original shooter)
-
- Posts: 8
- Joined: Sun Nov 12, 2023 5:42 am
- Preferred Pronouns: He/Him
Re: Is there any hitscan laserbeam-like function that has autoaim?
Thank you! That worked well.
-
- Posts: 8
- Joined: Sun Nov 12, 2023 5:42 am
- Preferred Pronouns: He/Him
Re: Is there any hitscan laserbeam-like function that has autoaim?
I noticed that the aimed missiles seem to go to the enemies' feet. Is there any way to make them aim for their centers?
-
-
- Posts: 1822
- Joined: Sun Jul 21, 2019 8:54 am
Re: Is there any hitscan laserbeam-like function that has autoaim?
That shouldn't be happening, could you show your code?