Shotgun projectiles

Vlaxep

Active member
Hi,

How can I make my shotgun fire 6 projectiles at once with spread? I tried burst fire with 0 delay but it just fires them at very fast intervals still?!

Am I missing something? I don't see any parameters in the projectile script nor shootable weapon script to cater to shotgun...
 
1604496700860.png

I just added the rocket projectile to the demo scene's shotgun and it basically works fine. Obviously you'll need to ensure that the rocket projectiles don't immediately collide with each other when firing (i.e. with the projectile start/fired layers), and the spread will probably need to be a bit higher to become really noticeable with thicker projectiles.
 
Hmmm thanks @Andrew I don't understand how the layer thing works... Maybe that's what's happening to my custom projectile?

I tried one variation where clearly my multiple projectiles were colliding and being destroyed instantly, but when I set a single projectile with fire rate 6 I just get a single projectile....

I'll give it a go with Opsive rocket projectile, but maybe you could explain how it would work with the layer thingo?
View attachment 4222

I just added the rocket projectile to the demo scene's shotgun and it basically works fine. Obviously you'll need to ensure that the rocket projectiles don't immediately collide with each other when firing (i.e. with the projectile start/fired layers), and the spread will probably need to be a bit higher to become really noticeable with thicker projectiles.
 
I'm just thinking no matter what I set the layer to won't they still collide with each other? Can you set each to different layer?
 
So below is how I've attempted this with rocket as you suggested @Andrew.

What I get is an explosion as soon as I fire (and nearly 50% health lol) and only one rocket appears to project forward. I'm guessing others are colliding and causing teh explosion.

Have played with the layer settings and delay, but still can't get a result......

1604543510290.png
 
This is to do with your project's collision matrix, which you can edit in Project Settings --> Physics --> scroll to the bottom. To avoid editing the collision matrix of any of the default layers, I'd recommend creating a new layer, e.g. "Rocket", and prevent this layer from colliding with itself by unchecking the "Rocket/Rocket" box, like so:

1604578116349.png

Then you can set this layer as the "Projectile Start Layer" in your ShootableWeapon component, so that when the rockets fire, they can still collide with other layers (as defined in the collision matrix), but not with each other.

You may even want to just have the rockets stay on this layer to prevent any other cases where they might collide with each other.
 
Hey @Andrew I don't understand why but this just does not work! I don't get it.

I even tried unchecking the entire row/column sow the 'Rocket' layer can't collide with any other layers, and I still get explosion at fire point and one rocket/projectile firing out.

This really does seem like it should work, but no dice.

I've even changed the projectile prefab layer to match, and set the 'Start' and 'Fired' layer to same also......
 
SOLVED

Dunno exactly what fixed this but I changed a few things.

So... using the layer 'ShotgunProjectiles'

Projectile Prefab set layer to 'ShotgunProjectiles
Projectile Prefab > Impact Layers > removed 'ShotgunProjectile'
Weapon > ShootableWeapon Script > Projectile Start+Fire Layers set to 'ShotgunProjectiles'
Weapon > ShootableWeapon Script > Impact Layers removed 'ShotgunProjectiles'
ProjectSettings > Physics and Physics 2D > Unchecked 'ShotgunProjectiles' to 'ShotgunProjectiles'

Now it seems to work correctly!

Thanks @Andrew you set me on the right path
 
Great!

For reference, I was getting the 6 projectiles before but they were exploding with each other on the first frame so you could only actually see 1 - I'm assuming that's what happened with you too.

Glad you figured it out!
 
If anyone comes across this and has the time to report back on exactly what makes this work, please comment!

I'm hoping what I've done doesn't have implication later in my game, changing layers and impact layers of a bunch of things....
 
Top