Retain velocity from a spawned... spawner.

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
Grey-Wolf
Posts: 179
Joined: Sun Jul 15, 2018 4:59 pm
Graphics Processor: nVidia (Modern GZDoom)

Retain velocity from a spawned... spawner.

Post by Grey-Wolf »

TNT1 A 0 A_print("Hello world! Yes, it's me. AGAIN")



I got a lootable closed chest up and working and now I'm writing the loot spawners for when it is opened by the player:
Spoiler:
Now, here's the catch: each one of the "loot" objects is a random spawner that picks between different items of the same type (of course armor, ammo, and healing items). Since this is just a prototype (there will be more spawn states with more loot combinations of three) and I want them to be randomized, I want those items to retain the velocity of the "loot" spawner actors written above, so the loot won't clip with itself and the three categories always pop up in those 3 directions. Is it possible?

Maybe a pointer with change_velocity? But how can I get the spawner point to the lootable spawned item from the spawner?
User avatar
KeksDose
 
 
Posts: 596
Joined: Thu Jul 05, 2007 6:13 pm
Location: my laboratory

Re: Retain velocity from a spawned... spawner.

Post by KeksDose »

If you're using RandomSpawner, you may override PostSpawn. There, you can transfer the velocity to the spawned thing.

Code: Select all

override void PostSpawn (Actor spawned) {
   spawned.vel = vel;
} 
That's in zs, though.

edit: You don't even need that. RandomSpawner already does it and it's available in decorate.
Last edited by KeksDose on Sun Feb 10, 2019 5:29 am, edited 1 time in total.
User avatar
Grey-Wolf
Posts: 179
Joined: Sun Jul 15, 2018 4:59 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Retain velocity from a spawned... spawner.

Post by Grey-Wolf »

Nope, just decorate.
These are some example of spawners:
Spoiler:
I used the "velx,vely,velz" and managed to make the items inherit the spawner's velocity, but there's another problem now: if the player is not facing what the MAP "thinks" X and Y are, the items will actually spawn behind and in front of the player, rather than at its left and right. Is there some way to make the velocities point at the player?
User avatar
KeksDose
 
 
Posts: 596
Joined: Thu Jul 05, 2007 6:13 pm
Location: my laboratory

Re: Retain velocity from a spawned... spawner.

Post by KeksDose »

If you can make the open crate face towards player, A_SpawnItemEx will do the rest for you. That depends on how the open crate is spawned. It might be as simple as A_FaceTarget before spawning the open crate (with A_SpawnItemEx).
User avatar
Grey-Wolf
Posts: 179
Joined: Sun Jul 15, 2018 4:59 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Retain velocity from a spawned... spawner.

Post by Grey-Wolf »

This is what the crate looks like right now:
Spoiler:
And this is one of the many spawner types: I added the absolutevelocity flag hoping that something would change.
Spoiler:
But they still spawn toward a fixed direction.

EDIT: here's some screenshots of what happens: no matter the starting position of the player when he opens them (I tried approaching the crates from different directions), the items always spawns "to the left" of the map.
Spoiler:
User avatar
KeksDose
 
 
Posts: 596
Joined: Thu Jul 05, 2007 6:13 pm
Location: my laboratory

Re: Retain velocity from a spawned... spawner.

Post by KeksDose »

As I said, it might be as simple as A_FaceTarget before spawning the open crate. The open crate might have no target. That depends on how the closed crate spawns the open one, and how the closed crate is spawned, so a target may be transferred to begin with. Show the closed crate and how it is spawned.

The loot is not so interesting, cuz giving it velocity happens way earlier in the spawn chain. We need the player, which is information clearly used way earlier, cuz somehow, the closed crate has to spawn the open one. If it doesn't care about a specific player at all, we might have a bad problem.

For example, the approach can easily work if the closed crate is spawned by a dying monster. A_SpawnItemEx can then transfer the monster's target to the closed crate. Then A_FaceTarget before spawning the open crate will do the trick.

Don't use absolute velocity, either. It prevents using the crate's angle for velocity and then the same thing will keep happening.
User avatar
Grey-Wolf
Posts: 179
Joined: Sun Jul 15, 2018 4:59 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Retain velocity from a spawned... spawner.

Post by Grey-Wolf »

Ok, here's the closed crate and the key item:
Spoiler:
User avatar
KeksDose
 
 
Posts: 596
Joined: Thu Jul 05, 2007 6:13 pm
Location: my laboratory

Re: Retain velocity from a spawned... spawner.

Post by KeksDose »

Fantastic! You're even using the target already. This here should already do the trick:

Code: Select all

// Spawn the open crate like this:
TNT1 A 0 A_FaceTarget
TNT1 A 0 A_SpawnItem("OpenCrate", 0) 
A_SpawnItem will transfer the closed crate's direction, and A_SpawnItemEx will use this for the velocity if you didn't set SXF_ABSOLUTEVELOCITY.

edit: had a ; where it doesn't belong huhu
User avatar
Grey-Wolf
Posts: 179
Joined: Sun Jul 15, 2018 4:59 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Retain velocity from a spawned... spawner.

Post by Grey-Wolf »

You... you life-saving bastard...

https://i.imgur.com/njobuYV.gif

Well, thanks A LOT. I don't think there's anything else to say.

Return to “Scripting”