A_SpawnItemEx to spawn actor in front of player's face

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
Jekyll Grim Payne
 
 
Posts: 1081
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

A_SpawnItemEx to spawn actor in front of player's face

Post by Jekyll Grim Payne »

Perhaps A_SpawnItemEx isn't the best function for it but I don't know another one. (In DECORATE anyway.)

So, let's say I want to spawn a decorative object, like a particle muzzle flash, in front of the player's face. A_SpawnItemEx spawns an actor relative to another actor, but there's no (easy and reliable) way to tie the spawning position to the player's direction of looking.

A_FireProjectile (or the old A_FireCustomMissile) does this, but it has its own drawbacks, namely it doesn't allow to set how close to the actor the object spawns and doesn't allow transferring the player's momentum to it.
User avatar
ramon.dexter
Posts: 1552
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: A_SpawnItemEx to spawn actor in front of player's face

Post by ramon.dexter »

Does it need to be directly in front of players face? I'm using the A_SpawnItemEx method with invisible actor and gldefs light.

But I can imagine something with the A_FireProjectile, just the projectile should have something like:

Code: Select all

States
{
    Spawn:
        TNT1 A 3
    Death:
        Stop
}
A projectile wil a really short lifespan. That should do the work. I think :)
User avatar
Jekyll Grim Payne
 
 
Posts: 1081
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Re: A_SpawnItemEx to spawn actor in front of player's face

Post by Jekyll Grim Payne »

ramon.dexter wrote:Does it need to be directly in front of players face? I'm using the A_SpawnItemEx method with invisible actor and gldefs light.
Yes, it does. It's a muzzle flash, so it should appear right at the end of player's gun sprite.

A projectile won't work because even with a short lifespan you can see it moving, coming out of you.
User avatar
Jekyll Grim Payne
 
 
Posts: 1081
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Re: A_SpawnItemEx to spawn actor in front of player's face

Post by Jekyll Grim Payne »

From my limited knowledge of trigonometry I figured the following function

Code: Select all

A_SpawnItemEx("Actorname",X*cos(pitch), 0, Z-X*sin(pitch), velx,vely,velz, 0, SXF_ABSOLUTEMOMENTUM) 
Where X is how far it should be from the actor and Z is how high it should be (for example, 10 and 40 respectively).

However, for some reason it still spawns a bit too high (relatively to the end of the gun sprite) when player's view is about 45 degrees above or below the horizon.

UPD:

Nevermind. I figured out how to tweak the math, but even with that using particle spawning for a muzzle flash effect has too many uncontrollable side-effects that make it look not too good.

Return to “Scripting”