Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: Adding inaccuracy to a beam?  (Read 496 times)

rogerbacon

  • Commander
  • ***
  • Posts: 151
    • View Profile
Adding inaccuracy to a beam?
« on: December 29, 2022, 03:54:50 PM »

I'd like a beam that 'rakes' across an area of space where it's aimed at instead of hitting with perfect accuracy. I tried editing the min.max spread in the csv but that's only for projectiles.

My thought now is to get the angle of the beam relative to the firing ship and move it +/- some amount every second. However, it seems all methods in BeamAPI are getters and not setters so I'm not sure how I would, programmatically, move the beams target point.
Any suggestions?
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 3803
    • View Profile
Re: Adding inaccuracy to a beam?
« Reply #1 on: December 29, 2022, 04:04:55 PM »

There are beam weapons that do exactly this in both Shadowyards and SCY; I'd suggest starting by taking a look at how they accomplish that.

Edit: I bet it's something like using the method to ensure a cloned weapon spec, and then changing the firing angle of the weapon's emitter point(s)? But I haven't gone to look myself.
« Last Edit: December 29, 2022, 04:09:43 PM by Wyvern »
Logged
Wyvern is 100% correct about the math.

mezzelo

  • Ensign
  • *
  • Posts: 10
  • lasher enthusiast
    • View Profile
Re: Adding inaccuracy to a beam?
« Reply #2 on: December 29, 2022, 09:46:08 PM »

You can achieve this by modifying the firing offsets of the weapon's emitters, yes.
Code
weapon.ensureClonedSpec();
/* multiple calls for the spec's different offsets, based on mount type */
weapon.getSpec().getTurretAngleOffsets().set(
0, /* offset index, iterate w/ loop if emitting multiple beams from one weapon */
arc * ((engine.getTotalElapsedTime(false) - sweepStart)/SWEEP_DURATION - 0.5f)
);

weapon.getSpec().getHardpointAngleOffsets().set(0,
arc * ((engine.getTotalElapsedTime(false) - sweepStart)/SWEEP_DURATION - 0.5f)
);
weapon.getSpec().getHiddenAngleOffsets().set(0,
arc * ((engine.getTotalElapsedTime(false) - sweepStart)/SWEEP_DURATION - 0.5f)
);
It's also possible to modify the weapon's angle itself if you want its graphic to move as well, although this approach restricts your offset to the mount's firing arc.
Code
weapon.setCurrAngle(
(initialFacing + arc * (((engine.getTotalElapsedTime(false) - sweepStart)/SWEEP_DURATION - 0.5f)) % 360f
);
However, it seems all methods in BeamAPI are getters and not setters so I'm not sure how I would, programmatically, move the beams target point.
iirc it's technically possible to modify the beam's end-point via Vector2f.add, but it's overwritten in execution order after the first frame or so of firing
Logged