Page 1 of 1

Flag for direction_only friendly fire.

Posted: Mon Aug 17, 2015 2:38 am
by AmbulatoryCortex
Certain weapons, like the cannon shell, damage friendly entities when fired through them. I'd like an entity flag to turn off impact with friendly entities, mainly for use in turrets. I think an entity flag would work best, as it would let us use the same projectile definition for turrets and other entities.

Re: Flag for direction_only friendly fire.

Posted: Wed Sep 21, 2016 5:06 pm
by kaldskryke
I'm sorry to necro an old post, but I came here to make a similar request and found this when I searched before creating a new topic.

I'm trying to modify "bullet" weapons to fire visible projectiles using the direction_only parameter and it works great... except that gun turrets can't shoot "over" walls. Without walls, it looks really cool to see crisscrossing streams of bullets flying out towards enemies, and combat with my SMG feels a lot more like a shoot-em-up game. I don't mind that my gun can't shoot over walls, and I kinda like that my gun turrets can mow me down if I'm not careful. But walls become kinda useless if my turrets can't shoot over them.

Re: Flag for direction_only friendly fire.

Posted: Thu Sep 22, 2016 2:30 pm
by bobingabout
kaldskryke wrote:I'm sorry to necro an old post, but I came here to make a similar request and found this when I searched before creating a new topic.

I'm trying to modify "bullet" weapons to fire visible projectiles using the direction_only parameter and it works great... except that gun turrets can't shoot "over" walls. Without walls, it looks really cool to see crisscrossing streams of bullets flying out towards enemies, and combat with my SMG feels a lot more like a shoot-em-up game. I don't mind that my gun can't shoot over walls, and I kinda like that my gun turrets can mow me down if I'm not careful. But walls become kinda useless if my turrets can't shoot over them.
Well... if you just want to see the projectile, you could do it the Laser/rocket projectile method, instead of the shotgun/tank shell method. The shotgun/tank shell use direction only, and depend on a collision box to determine if they've hit anything. The laser/rocket projectiles on the other hand are seeking, and do not require a collision box, as a result can shoot over walls.

There is also a 3rd type, Position I think, that is used on things like grenades, and other capsules that you throw. I have had limited success with that, weapons that fire automatically (Turrets and grid equipment) sometimes use the seeking method when targeting entities when set to position mode, but that might need further testing.

Re: Flag for direction_only friendly fire.

Posted: Thu Sep 22, 2016 3:15 pm
by aubergine18
You can see some of the firing mods illustrated in "Attack GIF" spoiler here: viewtopic.php?p=205572#p205572

Re: Flag for direction_only friendly fire.

Posted: Thu Sep 22, 2016 7:21 pm
by kaldskryke
I had written out a nice long response detailing my testing on the matter, but once again the factorio forums logged me out after X minutes of "inactivity". Logging in brought me back tot he "Post a Reply" page but my entire post was lost to the ether. I really need to get better at saving drafts before trying to post... or writing them in a different text editor?

I'll try to quickly paraphrase what I found. After some testing, I can speculate that:

EDIT: updated some incorrect information regarding collision checks.

The optional target_type element in the ammo_type table is used only to control how players select targets with their mouse cursor.
1) The "default" behavior, with target_type omitted is that the game looks for the hostile entity nearest to the cursor that is within max_range, and saves a reference to this entity as the target.
2) The "entity" target_type will only select an entity directly under the cursor. If no entity is present, firing does not occur. If there is an entity and it is within max_range, a reference is saved as the target.
3) The "position" target_type will check if the cursor is within max_range, and if so it will save the coordinates of this position as the target.
4) The "direction" target_type works similarly, except that the max_range is not checked. The position of the cursor is saved as the target.

AI controlled shooters (turrets/spitters/etc) ignore this data. They select entity targets based on their own algorithm (which might include pathfinding etc) and save a reference to the entity as a target.

After a target is selected, the ammo creates projectiles. Ammo info, such as repeat_count and direction_deviation etc. are used here, and every projectile created is given initial data of position, velocity, and a target (entity OR static position). The direction component of the initial velocity is determined by the target's position.

The projectiles themselves have no knowledge of the ammo_type that created them, and do not care what the ammo's target_type was. Every frame, a projectile travels according to its own logic:
1) the speed component of their velocity is adjusted by the acceleration parameter
2) the direction component of their velocity is adjusted such that it faces their target. This is obviously more interesting if the target is a moving entity; a stationary entity or a static position will result in a straight trajectory.
3) the position is updated according to the velocity
4) the projectile checks for collision with other entities according to its collision box. If it collides, its action table is executed.
5) if it reaches its target, its action table is executed
6) if it reaches the projectile's max_range its action table is executed

Note:
- Projectiles with an entity target will "seek" to their position. This is why laser bolts hilariously follow targets.
- Projectile max_range doesn't need to match the ammo max_range. The ammo max_range is used when targetting only.
- Contrary to my intuition, shooting ammo with the "direction" target_type still provides the projectile a position target (your mouse cursor). If the cursor was closer than the projectile max_range, the projectile will still stop where the cursor was.
- Grenades, laser beams, etc. don't collide with objects since they have no collision box defined.
- Projectiles without collision boxes can only "collide with" an entity if the entity is its target.

If the direction_only flag is set on the projectile, it overrides the projectile's behavior by discarding the "target" information. It's movement is therefore now dependent on direction only. Go figure. Steps (2) and (5) are skipped. Step (4) is still done.

Note:
- The shotgun uses the "direction" target_type, but its pellets also use direction_only. This isn't redundant, if direction_only was not set the pellets would stop at the mouse cursor rather than continuing to their max_range.
- The direction_only flag is the only way to get an AI shooter to fire in a straight line (not seeking)
- A projectile with direction_only set and no collision box cannot hit anything and always travel to its max_range

If what I've speculated above is true, it would be really helpful if the developers could make a couple (hopefully small?) changes:
1) make it so AI-controlled shooters can optionally emulate the "position" target_type and pass the position of their target entity to the projectiles rather than the entity itself. As an example use case: turrets/mortars that can fire grenades that don't collide before reaching a static target position, without seeking an entity.
2) add a friendly-fire flag to projectiles that will cause the projectile to ignore collisions with entities on the same force.

Re: Flag for direction_only friendly fire.

Posted: Thu Sep 22, 2016 7:37 pm
by kaldskryke
bobingabout wrote:
kaldskryke wrote:I'm sorry to necro an old post, but I came here to make a similar request and found this when I searched before creating a new topic.

I'm trying to modify "bullet" weapons to fire visible projectiles using the direction_only parameter and it works great... except that gun turrets can't shoot "over" walls. Without walls, it looks really cool to see crisscrossing streams of bullets flying out towards enemies, and combat with my SMG feels a lot more like a shoot-em-up game. I don't mind that my gun can't shoot over walls, and I kinda like that my gun turrets can mow me down if I'm not careful. But walls become kinda useless if my turrets can't shoot over them.
Well... if you just want to see the projectile, you could do it the Laser/rocket projectile method, instead of the shotgun/tank shell method. The shotgun/tank shell use direction only, and depend on a collision box to determine if they've hit anything. The laser/rocket projectiles on the other hand are seeking, and do not require a collision box, as a result can shoot over walls.

There is also a 3rd type, Position I think, that is used on things like grenades, and other capsules that you throw. I have had limited success with that, weapons that fire automatically (Turrets and grid equipment) sometimes use the seeking method when targeting entities when set to position mode, but that might need further testing.
For player handheld guns, I really like how using the "direction" target_type and direction_only projectiles removes the sense of "autoaim". Projectiles can actually miss! Especially with a little direction_deviation on the ammo. I'd hate to give that up, so I guess I'll give turrets their own ammo-type (ammo-belt) and projectile type and treat them kinda like laser turrets. Turrets "auto-aim" anyway, and if the bullets are fast you can't see them "seeking".

Last night I was also experimenting with direction_only spitter/worm acid projectiles. Players can now actually dodge attacks! I tweaked movement speed, projectile speed, and gun-movement-slowdown until I had a situation where I had to carefully switch between dodging attacks and standing-and-shooting. I also added an acid-damage-over-time entity where the projectiles hit, just to increase the importance of keeping mobile. It was actually really fun! But of course it was ruined by issues with friendly-fire. Particularly, worms kept killing spawners.

I thought I'd try to change the acid projectiles to be like grenades. I set the target_type to "position" and removed the collisionbox, but of course the projectiles just flew past where I was standing instead of stopping at the correct position. So I did a bunch more testing and found out that the "position" target_type doesn't actually get used by AI-controlled shooters, it's just for interface behavior. My findings are all in my last post. It explains why you were have troubles with your turrets and grid equipment still "seeking".