source_offset for projectiles

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

source_offset for projectiles

Post by Deadlock989 »

Hi,

When you're setting up a new turret, you want the projectiles to look like they're coming out of the barrel of the weapon. You can specify two different source_offset parameters in two different places. One (not in the wiki) is in the top level of the turret's attack_parameters and seems to regulate how "high" the turret barrel is, i.e. how far from the centre of the sprite the barrel's centre of rotation is - vanilla turrets all use a negative y offset for this. The second is in the action_delivery bit of the action in the ammo_type used by the turret and seems to regulate how far on the horizontal plane from the "centre" of the turret the projectile starts. Again, it's specified as a negative y vector, and then it appears to be rotated by the game depending on the turret's direction.

Questions:

1. Is there a system for figuring out these values based on the sprites of your turret? I'm just doing it by eye and tweaking values and it's irritating. I've tried calculating the offset in pixels based on the sprite (as if it were a shift parameter) but it doesn't produce consistent results.

2. The isometric view means that movement in the fake Y axis is foreshortened. Does the rotation of the projectile start position account for this automatically? On one of my turrets (a beam turret) it looks like it does, on another it looks like it doesn't (a projectile turret).

3. There are a few entities in the vanilla game that have a massive long table of offsets under headings like attacking_muzzle_animation_shift and projectile_creation_parameters. The flamethrower turret and artillery cannons are examples. What are these? They look like per-direction offsets, which makes me think that the answer to question 2 is "no". How can they be calculated - working out sin and cos values for every direction then squishing them by 1.414 for the isometric squish factor?
Image

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: source_offset for projectiles

Post by Deadlock989 »

No-one got any insight into this? I'm having to eyeball an array of eight turrets around a target and then tweaking the values manually and restarting the game every time I move a decimal.
Image

User avatar
mrudat
Fast Inserter
Fast Inserter
Posts: 229
Joined: Fri Feb 16, 2018 5:21 am
Contact:

Re: source_offset for projectiles

Post by mrudat »

I've been fiddling with things a little (scaling the vanilla turrets, and ending up with rather absurd numbers); as far as I can tell, there is an offset above the centre point of the turret (in tiles), and a radial offset from the centre point (also in tiles, I think), which is rotated with the turret.

In theory, you should be able to calculate the desired offset based on that data, I'm confident that my understanding of the height offset is accurate, but I haven't gotten the radial offset to line things up properly yet.

It's actually a bit more complicated than that; there are the offsets on the turret itself, but there are also offsets in the beam, stream and ammo prototypes as well.

For the laser turret, I have this suspicion that the offset you need to adjust is on the beam, not on the turret itself.

I believe that the vanilla muzzle flash is on the ammo, not on the gun turret, which may explain why fiddling with the offset on the gun turret doesn't make things line up correctly.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: source_offset for projectiles

Post by Deadlock989 »

You are right, it's different for beams and projectiles. For the latter you can also use projectile_center and projectile_creation_distance in the ammo type, because reasons.

What I'm not understanding is what the numbers mean. The horizontal offset does seem to relate to tile width, so 1.0 does offset by a tile. I can't figure out what the height offset is measured in. If it relates to tiles, I don't understand how.

I just want to be able to look at a sprite and figure out the offsets from that, not tweak four decimal places twenty times with a restart every time.
Image

User avatar
mrudat
Fast Inserter
Fast Inserter
Posts: 229
Joined: Fri Feb 16, 2018 5:21 am
Contact:

Re: source_offset for projectiles

Post by mrudat »

As far as I can tell, an entitie's 0,0 point is the center of the tiles the entity sits on.

The first offset is the distance between that point, and the point where the turret sprite's center of rotation is, in tiles.

It might be a useful thing to build a turret that's a circle and a line, centered on 0,0, then another centered on 0,-1, to see how things line up.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: source_offset for projectiles

Post by Deadlock989 »

Bumping this old thread because I've run into the same problem again, where I've moved a whole bunch of different turret sprites by a fixed amount to make their selection box centres more consistent, and it's a total nightmare adjusting both kinds of projectile/beam source offset ("height from ground" and distance from rotation centre) because I don't understand what these parameters actually do - if anyone has any insight from source code it'd be massively appreciated.
Image

PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

Re: source_offset for projectiles

Post by PyroFire »

Deadlock989 wrote:
Sun Apr 28, 2019 4:26 pm
Hi,
Hi.
Deadlock989 wrote:
Sun Apr 28, 2019 4:26 pm
When you're setting up a new turret, you want the projectiles to look like they're coming out of the barrel of the weapon. You can specify two different source_offset parameters in two different places. One (not in the wiki) is in the top level of the turret's attack_parameters and seems to regulate how "high" the turret barrel is, i.e. how far from the centre of the sprite the barrel's centre of rotation is - vanilla turrets all use a negative y offset for this. The second is in the action_delivery bit of the action in the ammo_type used by the turret and seems to regulate how far on the horizontal plane from the "centre" of the turret the projectile starts. Again, it's specified as a negative y vector, and then it appears to be rotated by the game depending on the turret's direction.
Confirmed not in wiki.

I haven't tested this, but you're asking for some insight so here goes.

It often helps to explicitly lay out the data you're working with, so let's do that first.

gun-turret.attack_parameters.projectile_center = {0,-0.0875}
gun-turret.attack_parameters.projectile_creation_distance = 1.39375

gun-turret.attack_parameters.shell_particle.center={-0.0625,0}
gun-turret.attack_parameters.creation_distance=-1.925

tank-machine-gun.attack_parameters.projectile_center={-0.15625,-0.078119999999999994}
tank-machine-gun.attack_parameters.projectile_creation_distance=1
tank-machine-gun.attack_parameters.shell_particle.center={0,0}
tank-machine-gun.attack_parameters.shell_particle.creation_distance=-0.6875

vehicle-machine-gun.attack_parameters.projectile_creation_distance=0.65
vehicle-machine-gun.attack_parameters.shell_particle.center={0,0}
vehicle-machine-gun.attack_parameters.shell_particle.creation_distance=-0.6875

projectile_center is the central position of the turret, and projectile_creation_distance is the distance from that position depending upon rotation.
A quick look at the tank barrel animation sheet.png confirms this.

.center and .creation_distance are actually in the shell_particle table, so those offsets are for the shell. Not the turret, the projectile nor the muzzle.

Seems straight forward so far.


Let's try electric.

laser-turret.attack_parameters.ammo_type.action.action_delivery.source_offset={0,-1.3143899999999}
laser-turret.attack_parameters.source_direction_count=64
laser-turret.attack_parameters.source_offset={0,-0.85587225}

It seems like these 2 offsets are referring to the projectile-source-center and the barrel itself, and having a look at the laser-turret-shooting.png confirms this - i can see there are 2 axis/circles at play here.
One for the physical barrel, and one for the "projectile-origin" of the barrel, because the "projectile-origin" is actually somewhat higher than the barrel's true position.
This can be seen best by the north facing turret is touching the edge of the sprite boundary, but with the south facing turret, the point where the beam should be made is somewhat closer to the center of the sprite.

Deadlock989 wrote:
Sun Apr 28, 2019 4:26 pm
Questions:

1. Is there a system for figuring out these values based on the sprites of your turret? I'm just doing it by eye and tweaking values and it's irritating. I've tried calculating the offset in pixels based on the sprite (as if it were a shift parameter) but it doesn't produce consistent results.
No, factorio cannot auto-magically figure out what sprites are or what their intended offsets should be.
They're just images which may as well be completely black squares as far as the engine is concerned.

Calculations are different, i'll get to that.
Deadlock989 wrote:
Sun Apr 28, 2019 4:26 pm
2. The isometric view means that movement in the fake Y axis is foreshortened. Does the rotation of the projectile start position account for this automatically? On one of my turrets (a beam turret) it looks like it does, on another it looks like it doesn't (a projectile turret).
Which one? there are several.

Deadlock989 wrote:
Sun Apr 28, 2019 4:26 pm
3. There are a few entities in the vanilla game that have a massive long table of offsets under headings like attacking_muzzle_animation_shift and projectile_creation_parameters. The flamethrower turret and artillery cannons are examples. What are these? They look like per-direction offsets, which makes me think that the answer to question 2 is "no". How can they be calculated - working out sin and cos values for every direction then squishing them by 1.414 for the isometric squish factor?
Those look like keyframes - a sequence of individual "shift" positions which the artillery-turret barrel will go through but that may not always be true for every other example.
The next table is probably to fix some alignment problems there under certain conditions/rotations: artillery-turret.cannon_barrel_recoil_shiftings_load_correction_matrix
Deadlock989 wrote:
Wed May 01, 2019 1:17 pm
I'm having to eyeball an array of eight turrets around a target and then tweaking the values manually and restarting the game every time I move a decimal.
This is normal.
I hate doing offsets too.
It may help to do what mrudat said afterwards - making temporary copies of prototypes for testing/debugging purposes - may help ease some of the pain involved with doing offsets.
mrudat wrote:
Wed May 01, 2019 3:13 pm
As far as I can tell, an entitie's 0,0 point is the center of the tiles the entity sits on.
The first offset is the distance between that point, and the point where the turret sprite's center of rotation is, in tiles.
It might be a useful thing to build a turret that's a circle and a line, centered on 0,0, then another centered on 0,-1, to see how things line up.
Deadlock989 wrote:
Wed May 01, 2019 2:48 pm
You are right, it's different for beams and projectiles. For the latter you can also use projectile_center and projectile_creation_distance in the ammo type, because reasons.

What I'm not understanding is what the numbers mean. The horizontal offset does seem to relate to tile width, so 1.0 does offset by a tile. I can't figure out what the height offset is measured in. If it relates to tiles, I don't understand how.

I just want to be able to look at a sprite and figure out the offsets from that, not tweak four decimal places twenty times with a restart every time.
It would typically be expected that the turret contains offsets that collectively point to the tip of the barrel.
Any other parameters that are found on the projectiles would be how that projectile itself needs to be positioned relative to the tip of the barrel.
Deadlock989 wrote:
Thu Nov 07, 2019 1:27 pm
Bumping this old thread because I've run into the same problem again, where I've moved a whole bunch of different turret sprites by a fixed amount to make their selection box centres more consistent, and it's a total nightmare adjusting both kinds of projectile/beam source offset ("height from ground" and distance from rotation centre) because I don't understand what these parameters actually do - if anyone has any insight from source code it'd be massively appreciated.
Systematically changing prototype sprite scales, collision boxes etc is relatively simple.
See functioning example here, where i've resized literally everything (as best i can - it's not finished) to 1x1.
These projectile center offsets will need to be added to my resizing code at some point.

https://mods.factorio.com/mod/nanotorio

Image

Bilka
Factorio Staff
Factorio Staff
Posts: 3133
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: source_offset for projectiles

Post by Bilka »

Deadlock989 wrote:
Sun Apr 28, 2019 4:26 pm
You can specify two different source_offset parameters in two different places. One (not in the wiki) is in the top level of the turret's attack_parameters and seems to regulate how "high" the turret barrel is, i.e. how far from the centre of the sprite the barrel's centre of rotation is - vanilla turrets all use a negative y offset for this.
PyroFire wrote:Confirmed not in wiki.
There is no such thing that is always being loaded by the game. The source_offset is only loaded in the documented cases: Beam attack params, beam trigger delivery, stream trigger delivery.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Modding help”