[Zscript] Bullet Casing ignores player pitch and movement

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!)
Post Reply
User avatar
OddYokai
Posts: 15
Joined: Mon Jul 04, 2022 11:01 am
Preferred Pronouns: He/Him
Graphics Processor: ATI/AMD (Modern GZDoom)
Location: Hungary
Contact:

[Zscript] Bullet Casing ignores player pitch and movement

Post by OddYokai »

Hi everyone, as you can see in the video, the bullets ejected ignore the player's pitch and movement

VIDEO:
https://youtu.be/O2VF3TYj4tc?si=2YRpKHJeRYGt21-3


The code is:

Code: Select all

 
		MCHF B 2 BRIGHT A_FireProjectile("BulletCasing", Random(-45,-25), 0, -6,FPF_NOAUTOAIM  ,180);
How can I make it better? Bullet casing lags behind the player's movement. If the player faces up, the bullet cases do not take this into account. If the player moves , bullet casing, will fall behind

SORRY FOR MY BAD ENGLISH!
User avatar
JUSSOMONE
Posts: 43
Joined: Fri Oct 07, 2022 8:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

Re: [Zscript] Bullet Casing ignores player pitch and movement

Post by JUSSOMONE »

Good afternoon, recently I've just launched my marathon mod and if I not mistaken, it has a similar but a more functional code regarding what you wish for, but let me help you:

1º The bullets "lag" is due to the -6 making the casing spawn at the left side of the weapon under the sprite
2º You seem to have mismatched the Spawnheight with flags, according to the wiki here is the function:

Code: Select all

action Actor, Actor A_FireProjectile(class<Actor> missiletype, double angle = 0, bool useammo = true, double spawnofs_xy = 0, double spawnheight = 0, EFireCustomMissileFlags flags = 0, double pitch = 0)
As you can see the Spawnheight and flags have swapped places, so in effect, nothing will happen.

Now about making it better:

1º Instead of spawning the casing directly from the function, you could create a dummy spawner to have more control of it with the same A_FireProjectile fuction, but you will relegate the angle, spawnheight and pitch to the spawner.

Code: Select all

TNT1 A 0 A_FireProjectile("MyCasingSpawner", 0, 0, 8, 0)

Code: Select all

actor MyCasingSpawner --> THE DUMMY SPAWNER
{
    Radius 1
    Height 1
    Speed 25 --> AS THE SPEED INCREASES, SO DOES THE FRONTAL SPAWN DISTANCE WITH THE PLAYER
    PROJECTILE
    +CLIENTSIDEONLY
    States
    {
      Spawn:
        TNT1 A 1
        TNT1 A 0 A_Die
        Goto Death

      Death:
        TNT1 A 0 A_SpawnProjectile("Casing",1,0,random(-80,-110),2,random(-30,-40))
        Stop
    }
}
2º By using the A_SpawnProjectile you will have a better control of it, since it will automatically track the player movement and pitch(not sure, but seem to have worked for me), then the only thing left to do is to finally "spawn" the true casing with the sprites and custom functions such as bounce type, factor, speed, and so on.

Code: Select all

actor Casing
{ 
    Scale 0.10
    Radius 3
    Height 3
    Speed 7 --> CONTROLS HOW FARTHER THE CASING IS LAUNCHED FROM THE DUMMY SPAWNER
    Mass 5
    bouncetype "doom"
    BounceFactor 0.4
    seesound " "
    Bouncesound "pistol/casing"
    +DROPOFF 
    +MISSILE 
    +NOTELEPORT 
    +MOVEWITHSECTOR
    -NOGRAVITY
    +FORCEXYBILLBOARD   
    States
    {
      Spawn:
        PBLT ABCDEF 1
        Loop

      Death:
        PBLT E 500
        PBLT EEEEEEEEEEEEEEEEEEEE 1 A_FadeOut(0.05)
        Stop
    }
}
Even still, there is some things that I really don't understand well, but you will learn eventually with experimentation and by reading the wiki pages, hope this helps.
User avatar
OddYokai
Posts: 15
Joined: Mon Jul 04, 2022 11:01 am
Preferred Pronouns: He/Him
Graphics Processor: ATI/AMD (Modern GZDoom)
Location: Hungary
Contact:

Re: [Zscript] Bullet Casing ignores player pitch and movement

Post by OddYokai »

As you can see the Spawnheight and flags have swapped places, so in effect, nothing will happen.
I am terribly careless, how did I not notice this all this time? :shock:

Anyway.
This works perfectly, thanks!
User avatar
JUSSOMONE
Posts: 43
Joined: Fri Oct 07, 2022 8:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia (Modern GZDoom)

Re: [Zscript] Bullet Casing ignores player pitch and movement

Post by JUSSOMONE »

OddYokai wrote: Sat Jan 27, 2024 8:38 am
As you can see the Spawnheight and flags have swapped places, so in effect, nothing will happen.
I am terribly careless, how did I not notice this all this time? :shock:

Anyway.
This works perfectly, thanks!
Good Afternoon, glad it worked. Don't blame yourself for the mistake, it happens all the time, especially when the code gets a "little" extensive, it happened to me a lot of times so, yeah it sucks... :lol:
Post Reply

Return to “Scripting”