Question on Cannon Projectile collision

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
heyqule
Long Handed Inserter
Long Handed Inserter
Posts: 54
Joined: Sun Mar 05, 2017 1:35 am
Contact:

Question on Cannon Projectile collision

Post by heyqule »

I have "Air" units that based on collision_mask = {}. Rocket can hit them, but cannon-projectile can't. Why is that? :?

I tried adding data.raw['projectile']['cannon-projectile']['action']['ignore_collision_condition'] = true. That didn't do anything. I thought it would behave like adding it in type="area"

heyqule
Long Handed Inserter
Long Handed Inserter
Posts: 54
Joined: Sun Mar 05, 2017 1:35 am
Contact:

Re: Question on Cannon Projectile collision

Post by heyqule »

I found the issue.

I have to add collision_mask = { 'layer-33' } to air unit and then add the mask to the projectile in hit_collision_mask. eg. data.raw['projectile']['cannon-projectile']['hit_collision_mask'] = { 'train-layer', 'player-layer', 'layer-33'}

PFQNiet
Filter Inserter
Filter Inserter
Posts: 289
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Question on Cannon Projectile collision

Post by PFQNiet »

Avoid hard-coding collision masks. You don't know what other mods might be using it.

Instead, use this:

Code: Select all

air_unit_layer = require("collision-mask-util").get_first_unused_layer()
Then you can assign collision_mask = {air_unit_layer} and add it to the projectile.

heyqule
Long Handed Inserter
Long Handed Inserter
Posts: 54
Joined: Sun Mar 05, 2017 1:35 am
Contact:

Re: Question on Cannon Projectile collision

Post by heyqule »

oh nice! Thank you for this TIL.

andrei
Burner Inserter
Burner Inserter
Posts: 14
Joined: Tue Aug 27, 2019 8:32 pm
Contact:

Re: Question on Cannon Projectile collision

Post by andrei »

Hmm, I didn't know this either. Thanks, PFQNiet! I've sent a documentation improvement request for https://wiki.factorio.com/Types/CollisionMask to mention get_first_unused_layer.

Post Reply

Return to “Modding discussion”