Reflecting projectiles - slowdown, etc.

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!)
Post Reply
Heisanevilgenius
Posts: 95
Joined: Wed Dec 15, 2021 8:38 pm
Graphics Processor: nVidia (Modern GZDoom)

Reflecting projectiles - slowdown, etc.

Post by Heisanevilgenius »

So I have an enemy that can reflect projectiles and a special weapon the player can use that also reflects. It's possible and quiet easy for a projectile to bounce back and forth between them multiple times, but every time it's reflected, the projectile slows down until it's moving at a ridiculously slow pace. Trying to figure out a way to fix that. One solution I came up with was using A_changevelocity on the projectile's spawn state to make it go full speed. I set the X velocity to full speed while preserving z velocity. It's hacky, and it sort of fixes it? Except that by just changing the X velocity, it doesn't take into account pitch. So that means if the projectile is fired at a steep angle upwards, like straight up, the projectile turns almost at a right angle and ends up moving parallel to the ground.

Any ideas for how to solve this? Is there somewhere I can review the actual reflection mechanic? If reflecting reduces the speed by a specific amount, I could potentially fix it by just compensating for that. For instance, if reflect halves velocity, I could use A_changevelocity to double velocity when it's reflected and cancel that out.
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Reflecting projectiles - slowdown, etc.

Post by Player701 »

Keeping the original speed is simple, no complex calculations are required. The only problem is that the engine does not provide a hook to run custom code when a projectile gets reflected. You can work around this by watching the projectile's angle each tick, and adjust the speed only if it changes:

Code: Select all

class MyProjectile : Actor
{
    // TODO: Rest of projectile code goes here

    override void Tick()
    {
        double ang = Angle;

        Super.Tick();

        if (Angle != ang)
        {
            Vel = Vel.Unit() * Speed;
        }
    }
}
Heisanevilgenius
Posts: 95
Joined: Wed Dec 15, 2021 8:38 pm
Graphics Processor: nVidia (Modern GZDoom)

Re: Reflecting projectiles - slowdown, etc.

Post by Heisanevilgenius »

I've been sticking mostly to Decorate so far but maybe it's about time I switched over to Zscript. Seems like there's just so much more you can do with it. I only stuck with decorate because it's what I'm used to and a little more beginner-friendly. Thank you!
Post Reply

Return to “Scripting”