Fix incorrect object placement with A_SpawnItemEx

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.

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

Fix incorrect object placement with A_SpawnItemEx

Post by Jekyll Grim Payne »

If you use A_SpawnItemEx to spawn something like a light halo for a flying projectile, even if you use 0,0,0 coordinates, the halo will look like it appears in front of the projectile and then jitters back; it only looks absolutely right when you use 'freeze' command.

The same problem arises if you try to use FastProjectile and make the halo object spawn via MissileType: they jitter back and forth (if the projectile has a regular speed, not what FastProjectile is usually used for).

I decided to create a singular halo that just uses the same velocity as the projectile and dies with it. However, if it spawns at the same time as the projectile, it'll appear 24 units in front of it, not at the projectile's position (even with 0,0,0 coordinates). So I used this:

Code: Select all

Actor BD_Plasmaball : Plasmaballreplaces Plasmaball
{  
+DONTBLAST
damagetype PlasmaDamage
+FORCEXYBILLBOARD
+THRUGHOST
+NOEXTREMEDEATH
+BLOODLESSIMPACT
decal BluePlasmaSplat
renderstyle ADD
scale .2
alpha .5
States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_SpawnItemEx("BlueFlarePlasma",-24,0,0,velx,vely,velz,0,SXF_SETMASTER|SXF_ORIGINATOR|SXF_ABSOLUTEVELOCITY)
		PLBA ABCDEF 2 bright
		goto spawn+2
	}
}

Actor BlueFlarePlasma
{
+NOINTERACTION
+NOGRAVITY
renderstyle Add
alpha .5
scale .1
states
	{
	Spawn:
		LENB A 1bright
		loop
	}
}
It does look like the halo is perfectly matched to the projectile... As long as you're shooting horizontally. If you shoot diagonally up or down, the halo will naturally be skewed in space.

Is there any way I could adjust the formula so that it appears in its proper place?


For reference, if I use 0,0,0 coordinates, it'll look like this (this is view from the side with 'freeze', not from behind):



Note that in this case the halo somehow spawns in front of the projectile but it DOES take its pitch into account; while according to the wiki it's impossible to truly account for projectile's pitch.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Fix incorrect object placement with A_SpawnItemEx

Post by Apeirogon »

Try warp instead spawn, like

Code: Select all

Actor BD_Plasmaball : Plasmaballreplaces Plasmaball
{ 
+DONTBLAST
damagetype PlasmaDamage
+FORCEXYBILLBOARD
+THRUGHOST
+NOEXTREMEDEATH
+BLOODLESSIMPACT
decal BluePlasmaSplat
renderstyle ADD
scale .2
alpha .5
States
   {
   Spawn:
      TNT1 A 0 nodelay A_SpawnItemEx("BlueFlarePlasma",-24,0,0,velx,vely,velz,0,SXF_SETMASTER|SXF_ORIGINATOR|SXF_ABSOLUTEVELOCITY)
      miniloop
	  PLBA ABCDEF 2 bright a_warp(aaptr_master, 0,0,0,0, WARPF_NOCHECKPOSITION|WARPF_MOVEPTR|WARPF_INTERPOLATE|WARPF_WARPINTERPOLATION)
      loop
   }
}

Last edited by Blue Shadow on Mon Jan 22, 2018 9:17 am, edited 1 time in total.
Reason: Enabled BBCode.
User avatar
Jekyll Grim Payne
Global Moderator
Posts: 1120
Joined: Mon Jul 21, 2008 4:08 am
Preferred Pronouns: He/Him
Graphics Processor: nVidia (Modern GZDoom)

Re: Fix incorrect object placement with A_SpawnItemEx

Post by Jekyll Grim Payne »

Apeirogon wrote:Try warp instead spawn, like

It would make more sense to use A_Warp on the halo instead of the projectile, otherwise it'd change the position of the actual projectile. You're right, they can be combined (I tried A_Warp before but without combining it with this method), and it's very effective, it does indeed fix the halo's position. Thanks!
User avatar
krokots
Posts: 296
Joined: Tue Jan 19, 2010 5:07 pm

Re: Fix incorrect object placement with A_SpawnItemEx

Post by krokots »

I encountered this "jittering" in my projects. Did you try to change angle of the "effect" so that is angled always towards player? Maybe that will stop the jittering, but I don't know. I just left it as it is in my mod.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am

Re: Fix incorrect object placement with A_SpawnItemEx

Post by Void Weaver »

Apeirogon wrote:miniloop
o_0 What is "miniloop"?! I never saw such instruction before, how it work?
User avatar
Nash
 
 
Posts: 17510
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: Fix incorrect object placement with A_SpawnItemEx

Post by Nash »

Void Weaver wrote:
Apeirogon wrote:miniloop
o_0 What is "miniloop"?! I never saw such instruction before, how it work?
There is no such thing in the entire source code so I assume author made a mistake in that post.

(Source: every State-related instruction can be found inside ParseStates inside thingdef_states.cpp; on top of that, a global search for "miniloop" in the entire source code returns 0 results)
User avatar
Mikk-
Posts: 2274
Joined: Tue Jun 30, 2009 1:31 pm

Re: Fix incorrect object placement with A_SpawnItemEx

Post by Mikk- »

I think it’s supposed to be a custom state, however he forgot the Colon

Return to “Scripting”