Skip to content

Commit 1b8c43c

Browse files
committed
Fixed detached attachables on gibbing not inheriting velocity derived from spinning
1 parent b7bc8f9 commit 1b8c43c

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8383

8484
- Almost all ctrl+* special inputs functionality (i.e restarting activity, world dumps, showing performance stats) are now mapped to right alt, to not interfere with default crouching inputs. The only exception is ctrl+arrow keys for changing console size.
8585

86-
- Gibs now inherit velocity derived from the angular velocity of an MO. This only affects gibs with an offset, and is scaled by `InheritsVel`.
86+
- Gibs and Attachables detached due to gibbing now inherit velocity derived from the angular velocity of the parent MO. This only has an effect when the gib/attachable is offset, and gibs are further scaled by `InheritsVel`.
8787

8888
</details>
8989

Source/Entities/MOSRotating.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -943,9 +943,11 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
943943
Vector gibVelocity(radius * scale + minVelocity, 0);
944944
gibVelocity.RadRotate(randAngle + RandomNum(0.0F, spread) + static_cast<float>(i) * goldenAngle);
945945

946-
if (gibSettingsObject.InheritsVelocity() > 0 && !rotatedGibOffset.IsZero()) {
947-
Vector rotationalVelocity = (rotatedGibOffset.GetPerpendicular() * m_AngularVel * gibSettingsObject.InheritsVelocity()) / c_PPM;
948-
gibVelocity += rotationalVelocity;
946+
if (gibSettingsObject.InheritsVelocity() > 0) {
947+
if (!rotatedGibOffset.IsZero()) {
948+
Vector rotationalVelocity = (rotatedGibOffset.GetPerpendicular() * m_AngularVel * gibSettingsObject.InheritsVelocity()) / c_PPM;
949+
gibVelocity += rotationalVelocity;
950+
}
949951
gibParticleClone->SetAngularVel(gibParticleClone->GetAngularVel() + m_AngularVel * gibSettingsObject.InheritsVelocity());
950952
}
951953

@@ -1006,9 +1008,11 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
10061008
gibVelocity.RadRotate(gibSpread * RandomNormalNum());
10071009
}
10081010

1009-
if (gibSettingsObject.InheritsVelocity() > 0 && !rotatedGibOffset.IsZero()) {
1010-
Vector rotationalVelocity = (rotatedGibOffset.GetPerpendicular() * m_AngularVel * gibSettingsObject.InheritsVelocity()) / c_PPM;
1011-
gibVelocity += rotationalVelocity;
1011+
if (gibSettingsObject.InheritsVelocity() > 0) {
1012+
if (!rotatedGibOffset.IsZero()) {
1013+
Vector rotationalVelocity = (rotatedGibOffset.GetPerpendicular() * m_AngularVel * gibSettingsObject.InheritsVelocity()) / c_PPM;
1014+
gibVelocity += rotationalVelocity;
1015+
}
10121016
gibParticleClone->SetAngularVel(gibParticleClone->GetAngularVel() + m_AngularVel * gibSettingsObject.InheritsVelocity());
10131017
}
10141018

@@ -1034,6 +1038,12 @@ void MOSRotating::RemoveAttachablesWhenGibbing(const Vector& impactImpulse, Mova
10341038
RTEAssert(attachable, "Broken Attachable when Gibbing!");
10351039

10361040
if (RandomNum() < attachable->GetGibWithParentChance() || attachable->GetGibWhenRemovedFromParent()) {
1041+
float attachableGibBlastStrength = (attachable->GetParentGibBlastStrengthMultiplier() * m_GibBlastStrength) / (1 + attachable->GetMass());
1042+
attachable->SetAngularVel((attachable->GetAngularVel() * 0.5F) + (attachable->GetAngularVel() * 0.5F * attachableGibBlastStrength * RandomNormalNum()));
1043+
Vector gibBlastVel = Vector(attachable->GetParentOffset()).SetMagnitude(attachableGibBlastStrength * 0.5F + (attachableGibBlastStrength * RandomNum()));
1044+
Vector rotationalVelocity = ((attachable->GetPos() - m_Pos).GetPerpendicular() * m_AngularVel) / c_PPM;
1045+
attachable->SetAngularVel(attachable->GetAngularVel() + m_AngularVel);
1046+
attachable->SetVel(m_Vel + gibBlastVel + rotationalVelocity); // Attachables have already had their velocity updated by ApplyImpulses(), no need to add impactImpulse again
10371047
attachable->GibThis();
10381048
continue;
10391049
}
@@ -1042,7 +1052,9 @@ void MOSRotating::RemoveAttachablesWhenGibbing(const Vector& impactImpulse, Mova
10421052
float attachableGibBlastStrength = (attachable->GetParentGibBlastStrengthMultiplier() * m_GibBlastStrength) / (1 + attachable->GetMass());
10431053
attachable->SetAngularVel((attachable->GetAngularVel() * 0.5F) + (attachable->GetAngularVel() * 0.5F * attachableGibBlastStrength * RandomNormalNum()));
10441054
Vector gibBlastVel = Vector(attachable->GetParentOffset()).SetMagnitude(attachableGibBlastStrength * 0.5F + (attachableGibBlastStrength * RandomNum()));
1045-
attachable->SetVel(m_Vel + gibBlastVel); // Attachables have already had their velocity updated by ApplyImpulses(), no need to add impactImpulse again
1055+
Vector rotationalVelocity = ((attachable->GetPos() - m_Pos).GetPerpendicular() * m_AngularVel) / c_PPM;
1056+
attachable->SetAngularVel(attachable->GetAngularVel() + m_AngularVel);
1057+
attachable->SetVel(m_Vel + gibBlastVel + rotationalVelocity); // Attachables have already had their velocity updated by ApplyImpulses(), no need to add impactImpulse again
10461058

10471059
if (movableObjectToIgnore) {
10481060
attachable->SetWhichMOToNotHit(movableObjectToIgnore);

0 commit comments

Comments
 (0)