Projectile colliding with the player on spawn

Recommended Posts

I'm having trouble making a mod that adds projectile bullets to Doom. I have the bullets spawn in using an ACS script, but every time they do, they immediately collide with the player and disappear. Setting the NOCLIP flag fixes this, but then it doesn't collide with enemies or walls.

How do I make a projectile bullet that will collide with enemies but not with the player?

Share this post

Link to post

The only way would be to make the first parameter of SpawnProjectile use the player's own tid rather than that of a map spot. Then you won't have any option to spawn the projectile at an arbitrary height, though. You'd have to solve that problem via a custom weapon actor in DECORATE rather than via ACS.

EDIT: I can think of an ACS-only solution now: After spawning the projectile using the player's tid, change the projectile's position via SetActorPosition.

It seems to only be working with bullets pitched at an upwards angle. What I think is happening is that the downward facing bullets are spawning at doomguy's feet and then colliding with the floor before it gets a chance to set the position.

Is there some way that I can make the projectile invincible until I set a flag on it from within ACS? That way I can make sure it doesn't die before the position is set.

Share this post

Link to post

I'm not really sure if that would work, though. Iirc, if you spawn a projectile with something it can collide with, it'll collide with it immediately before doing anything else.

You might be better of doing some nonsense with spawning a projectile through a CustomInventory item given to the player, because that will definitely set the projectile's target before it finished spawning.

Share this post

Link to post

Thanks I tried this and it works. Now it's just a matter of tweaking everything.

Albertoni said:

Also, you might want to call UniqueTID only once for each player. You might run out of tids like that lol

It calls UniqueTID only once at the beginning of the spawn function, and then at the end of it calls Thing_ChangeTID to free up the TID by giving the bullet a TID of 0. Is that okay or is there a better way of doing it?

Share this post

Link to post

It -should- be okay. If you want to be really sure it's okay, change your code to
UniqueTID(10000);
That way, you'll get an almost-100%-unique TID. Then print the TID to the console or the screen. If after a second you get the same TID, then it's (almost) good.

What do I mean by almost? Well, if your mod is intended to be compatible with ZDoom stuff, you might want to change the code to UniqueTID(0, 1000);. Since in ZDoom things can have IDs, you might run into compatibility problems. Read the Parameters part of the wiki: https://zdoom.org/wiki/UniqueTID

Sorry if I'm hard to understand, I't's almost 3:30AM here and I was just giving the last check of the night to some sites, feel free to ask if I said something confusing or didn't make sense :)

Share this post

Link to post

It calls UniqueTID only once at the beginning of the spawn function, and then at the end of it calls Thing_ChangeTID to free up the TID by giving the bullet a TID of 0. Is that okay or is there a better way of doing it?

I've resorted to multiplying the bullet horizontal speed by an arbitrary value of 10 because for some reason there isn't a 1:1 ratio between vertical and horizontal speeds. It's causing my bullets to drift towards the horizon rather than ascending/descending at the correct rate. What ratio should I be using instead, and why the heck can't I pass the same values to SetActorVelocity as I do to SpawnProjectile?

Also I think a significant amount of accuracy is being lost by the horizontal angle conversion ( int ang = GetActorAngle(0)>>8; )

The more I tweak this the more broken it becomes. Zdoom's data types are really starting to piss me off. I need help :(

Share this post

Link to post

The ratio should be 1:1. Try setting both the projectile's speed and vspeed within SetActorVelocity - you might need some sin/cos functions for the velx/vely parameters, but you'll also achieve higher accuracy. I'm also not sure if you need to use SetActorPitch at all. Also, isn't the projectile's DECORATE-coded behavior influencing its movement somehow?

Gamer With Dignity said:

why the heck can't I pass the same values to SetActorVelocity as I do to SpawnProjectile?

SpawnProjectile is based on Thing_Projectile, which was inherited from Hexen, which is 20+ years old and its parameter values were limited to range 0-255, whereas SetActorVelocity is a newer ZDoom-specific function that can handle fixed point numbers.

Gamer With Dignity said:

Also I think a significant amount of accuracy is being lost by the horizontal angle conversion ( int ang = GetActorAngle(0)>>8; )

Share this post

Link to post

The ratio should be 1:1. Try setting both the projectile's speed and vspeed within SetActorVelocity - you might need some sin/cos functions for the velx/vely parameters, but you'll also achieve higher accuracy.

Yeah I was hoping that I would be able to get by without having to use trig functions to set two components of lateral velocity, but I guess that's not gonna happen.

scifista42 said:

I'm also not sure if you need to use SetActorPitch at all.

If you take a look at the mod itself, pitch is used in determining which voxel models the bullet should use. I created different models for the bullets ranging a full 180 degrees of pitch, with one model per every 10 degrees. I could change it to use a custom inventory though. The decision to use pitch is an arbitrary one.

I don't think so since calling SpawnProjectile from ACS and specifying 0 for each velocity just results in a motionless bullet. And I doubt the DECORATE is having a multiplicative effect on speed but I could be wrong.

scifista42 said:

SpawnProjectile is based on Thing_Projectile, which was inherited from Hexen, which is 20+ years old and its parameter values were limited to range 0-255, whereas SetActorVelocity is a newer ZDoom-specific function that can handle fixed point numbers.

Very interesting! I'll keep that in mind.

scifista42 said:

And also by this: ( speed>>16 )

I'm probably going to find a way to fix the precision loss problem on my own, I just haven't put any thought into it yet. I'll try to get this one done by Thanksgiving.

Share this post

Link to post

Now I realized, according to their wiki pages, the velocities in SpawnProjectile and Thing_Projectile are given in "units per 8 tics", whereas the velocities in SetActorVelocity are presumably given in units per 1 tic, so you might be able to avoid trig functions if you just change your arbitrary value 10 to 8.