Skip to content

Commit

Permalink
Implement a Dual Yaw turret controller so that Loyalist can fully aim…
Browse files Browse the repository at this point in the history
… its secondary (#6428)

The secondary used to be unable to aim the body.
Also fix the secondary getting stuck on T1 units when the primary is aiming at a higher tech unit in a different direction.
  • Loading branch information
lL1l1 authored Oct 22, 2024
1 parent afa3c44 commit d1e6a39
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
4 changes: 4 additions & 0 deletions changelog/snippets/features.6428.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- (#6428) Implement a Dual Yaw turret controller so that Loyalist can fully aim its secondary.

Previously, the Loyalist was unable to aim its secondary weapon in all directions because the secondary weapon could not rotate the torso independently.
With this change, a weapon can have a secondary yaw bone to aim with by defining `TurretBoneDualYaw` in its blueprint. The secondary yaw's angle, range, and speed can be set with `TurretDualYaw`, `TurretDualYawRange`, and `TurretDualYawSpeed`, but they also default to the primary yaw's angle, range, and speed if not specified.
8 changes: 8 additions & 0 deletions engine/Core/Blueprints/WeaponBlueprint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@
---@field TurretBoneDualMuzzle? Bone
--- the second pitch bone for a turret, used for arms on bots as weapons
---@field TurretBoneDualPitch? Bone
--- The second yaw bone for a turret, used for the torso of the Loyalist's secondary weapon that is on a turret connected to the torso.
---@field TurretBoneDualYaw? Bone
--- The bone used as the muzzle bone for turrets. This is used for aiming as where the projectile
--- would come out
---@field TurretBoneMuzzle? Bone
Expand All @@ -342,6 +344,12 @@
---@field TurretYawRange number
--- the speed at which the turret can turn in its yaw direction
---@field TurretYawSpeed number
--- the center angle for determining secondary yaw, based off the rest pose of the model
---@field TurretDualYaw number
--- the angle +/- off the secondary yaw that is a valid angle to turn to
---@field TurretDualYawRange number
--- the speed at which the secondary turret can turn in its yaw direction
---@field TurretDualYawSpeed number
--- if this weapon uses the recent firing solution to create projectile instead of the
--- aim bone transform
---@field UseFiringSolutionInsteadOfAimBone? boolean
Expand Down
47 changes: 39 additions & 8 deletions lua/sim/weapon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Weapon = ClassWeapon(WeaponMethods, DebugWeaponComponent) {
local pitchBone = bp.TurretBonePitch
local muzzleBone = bp.TurretBoneMuzzle
local precedence = bp.AimControlPrecedence or 10
local pitchBone2, muzzleBone2
local pitchBone2, muzzleBone2, yawBone2

local boneDualPitch = bp.TurretBoneDualPitch
if boneDualPitch and boneDualPitch ~= '' then
Expand All @@ -147,6 +147,11 @@ Weapon = ClassWeapon(WeaponMethods, DebugWeaponComponent) {
if boneDualMuzzle and boneDualMuzzle ~= '' then
muzzleBone2 = boneDualMuzzle
end
local boneDualYaw = bp.TurretBoneDualYaw
if boneDualYaw and boneDualYaw ~= '' then
yawBone2 = boneDualYaw
end

local unit = self.unit
if not (unit:ValidateBone(yawBone) and unit:ValidateBone(pitchBone) and unit:ValidateBone(muzzleBone)) then
error('*ERROR: Bone aborting turret setup due to bone issues.', 2)
Expand All @@ -156,10 +161,15 @@ Weapon = ClassWeapon(WeaponMethods, DebugWeaponComponent) {
error('*ERROR: Bone aborting turret setup due to pitch/muzzle bone2 issues.', 2)
return
end
elseif yawBone2 then
if not unit:ValidateBone(yawBone2) then
error('*ERROR: Bone aborting turret setup due to yaw bone2 issues.', 2)
return
end
end
local aimControl, aimRight, aimLeft
local aimControl, aimRight, aimLeft, aimYaw2
if yawBone and pitchBone and muzzleBone then
local trashManipulators = self.Trash
local selfTrash = self.Trash
if bp.TurretDualManipulators then
aimControl = CreateAimController(self, 'Torso', yawBone)
aimRight = CreateAimController(self, 'Right', pitchBone, pitchBone, muzzleBone)
Expand All @@ -173,27 +183,36 @@ Weapon = ClassWeapon(WeaponMethods, DebugWeaponComponent) {
aimControl:SetResetPoseTime(9999999)
end
self:SetFireControl('Right')
trashManipulators:Add(aimControl)
trashManipulators:Add(aimRight)
trashManipulators:Add(aimLeft)
selfTrash:Add(aimControl)
selfTrash:Add(aimRight)
selfTrash:Add(aimLeft)
else
aimControl = CreateAimController(self, 'Default', yawBone, pitchBone, muzzleBone)
if EntityCategoryContains(categories.STRUCTURE, unit) then
aimControl:SetResetPoseTime(9999999)
end
trashManipulators:Add(aimControl)
selfTrash:Add(aimControl)
aimControl:SetPrecedence(precedence)
if bp.RackSlavedToTurret and not table.empty(bp.RackBones) then
for _, v in bp.RackBones do
local rackBone = v.RackBone
if rackBone ~= pitchBone then
local slaver = CreateSlaver(unit, rackBone, pitchBone)
slaver:SetPrecedence(precedence - 1)
trashManipulators:Add(slaver)
selfTrash:Add(slaver)
end
end
end
end

if yawBone2 then
aimYaw2 = CreateAimController(self, 'Yaw2', yawBone2, yawBone2)
aimYaw2:SetPrecedence(precedence-1)
if EntityCategoryContains(categories.STRUCTURE, unit) then
aimYaw2:SetResetPoseTime(9999999)
end
selfTrash:Add(aimYaw2)
end
else
error('*ERROR: Trying to setup a turreted weapon but there are yaw bones, pitch bones or muzzle bones missing from the blueprint.', 2)
end
Expand Down Expand Up @@ -232,6 +251,18 @@ Weapon = ClassWeapon(WeaponMethods, DebugWeaponComponent) {
aimRight:SetFiringArc(turretyawmin, turretyawmax, turretyawspeed, turretpitchmin, turretpitchmax, turretpitchspeed)
aimLeft:SetFiringArc(turretyawmin, turretyawmax, turretyawspeed, turretpitchmin, turretpitchmax, turretpitchspeed)
end

if aimYaw2 then
local turretYawMin2 = turretyawmin
local turretYawMax2 = turretyawmax
if bp.TurretDualYaw and bp.TurretDualYawRange then
turretYawMin2 = bp.TurretDualYaw - bp.TurretDualYawRange
turretYawMax2 = bp.TurretDualYaw + bp.TurretDualYawRange
end

local turretYawSpeed2 = bp.TurretDualYawSpeed or turretyawspeed
aimYaw2:SetFiringArc(turretYawMin2, turretYawMax2, turretYawSpeed2, turretpitchmin, turretpitchmax, turretpitchspeed)
end
else
local strg = '*ERROR: TRYING TO SETUP A TURRET WITHOUT ALL TURRET NUMBERS IN BLUEPRINT, ABORTING TURRET SETUP. WEAPON: ' .. bp.Label .. ' UNIT: '.. unit.UnitId
error(strg, 2)
Expand Down
5 changes: 5 additions & 0 deletions units/URL0303/URL0303_unit.bp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ UnitBlueprint{
MuzzleSalvoSize = 1,
MuzzleVelocity = 35,
NotExclusive = true,
PrefersPrimaryWeaponTarget = true,
ProjectileId = "/projectiles/CDFBolter02/CDFBolter02_proj.bp",
ProjectileLifetimeUsesMultiplier = 1.15,
ProjectilesPerOnFire = 1,
Expand Down Expand Up @@ -306,13 +307,17 @@ UnitBlueprint{
TurretBoneMuzzle = "Muzzle_Right",
TurretBonePitch = "Barrel_R",
TurretBoneYaw = "Barrel_R",
TurretBoneDualYaw = "Torso",
TurretDualManipulators = false,
TurretPitch = 0,
TurretPitchRange = 45,
TurretPitchSpeed = 90,
TurretYaw = 0,
TurretYawRange = 35,
TurretYawSpeed = 120,
TurretDualYaw = 0,
TurretDualYawRange = 180,
TurretDualYawSpeed = 120,
Turreted = true,
UseFiringSolutionInsteadOfAimBone = true,
WeaponCategory = "Direct Fire",
Expand Down

0 comments on commit d1e6a39

Please sign in to comment.