[Decorate/ZScript] Item that sticks to a door

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.

[Decorate/ZScript] Item that sticks to a door

Postby Mere_Duke » Mon Jun 03, 2019 9:40 pm

There is a Crossbow weapon in my Decorate. It fires +RIPPER projectiles. When projectile dies (on impact with a wall/floor/ceiling etc.), it spawns a static item representing an "arrow in a wall" prop. When it's stuck in a door (default doom up/down sliding door), the arrow won't move with that door when it opens up; instead, it will hang in air. How should I avoid this behavior? I need either make an arrow to move alongside a door, or make it fall to the ground. Or even stop it from spawning if it hits a door...
Preferably the case where it moves with the door it sticks in.

Flying arrow code:

Spawned arrow:
User avatar
Code Inspector
Joined: 28 Aug 2016
Location: Russia

Re: [Decorate/ZScript] Item that sticks to a door

Postby gramps » Mon Jun 03, 2019 10:51 pm

Just spitballing here, but you could try something like this:

- First, make sure the "arrow in wall" actor is actually in the moving sector. Make sure the tip of the arrow sprite is its world origin, and push it forward a little bit when it hits the wall.

- Next, check if it's below the floor or above the ceiling. If it's above the ceiling, it's in a door, and needs to move relative to ceiling. If it's below the floor, it's in a lift, and needs to move relative to floor. If it's between the floor and ceiling, it's probably
on a regular wall, so leave it there and stop here. *

- Store the distance between the arrow and the floor/ceiling, and whether it's in a door or lift. After you've stored it, update the position every tick so that it maintains the same distance to the floor/ceiling. Make it disappear after a while so you don't have too many of them stacking up.

Maybe there are better ways to peg it to a certain distance from floor/ceiling, not sure about that. I think the first step is the key to getting this to work.

* Maybe it's on a blocking midtexture line though, and that could be part of a moving platform. Not sure what to do about that.
Joined: 18 Oct 2018

Re: [Decorate/ZScript] Item that sticks to a door

Postby Matt » Tue Jun 04, 2019 9:25 am

The way I've been doing it is kinda brute-force so if anyone's got a better method I'd like to know as well.

1. Get the linedef that got hit.
2. Get the floor and ceiling heights of the sector on the other side.
3. Get whether the actor is under that floor or above that ceiling retrieved in #2.
4. Get the absolute height of the floor/ceiling in question, plus or minus the actor's own Z position, and save it in the actor's variables.
5. From that point on, call SetZ every tick to set the actor's Z position in the position that is equal to the current floor/ceiling height of the opposite sector, plus or minus the stored difference. If at any time this goes above the actor's own ceiling or below its own floor, clear the variable and stop calling SetZ.

Separate checks would be required for if the arrow were to hit the bottom of the door or the top of a platform, but those are simple enough.
User avatar
Putting the XD into *xdeath since 2007
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest