A_SpawnItemEx to spawn actor in front of player's face

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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.

A_SpawnItemEx to spawn actor in front of player's face

Postby Jekyll Grim Payne » Sat Dec 16, 2017 6:56 am

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
Jekyll Grim Payne
 
Joined: 21 Jul 2008

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

Postby ramon.dexter » Sat Dec 16, 2017 7:24 am

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 allExpand view
States
{
    Spawn:
        TNT1 A 3
    Death:
        Stop
}

A projectile wil a really short lifespan. That should do the work. I think :)
User avatar
ramon.dexter
rudebwoy
 
Joined: 20 Oct 2015
Location: Kozolupy, Bohemia

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

Postby Jekyll Grim Payne » Sat Dec 16, 2017 1:11 pm

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
 
Joined: 21 Jul 2008

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

Postby Jekyll Grim Payne » Sat Dec 16, 2017 5:23 pm

From my limited knowledge of trigonometry I figured the following function

Code: Select allExpand view
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.
User avatar
Jekyll Grim Payne
 
Joined: 21 Jul 2008


Return to Scripting

Who is online

Users browsing this forum: RSSwizard and 2 guests