Skip to content

Commit c432d78

Browse files
committed
Gibs and detached attachables now consider the root parent instead of immediate parent when calculating rotational velocity, to patch case of attachables gibbed/detached from attached attachables not inheriting rotational velocity.
1 parent 098bbf4 commit c432d78

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

Source/Entities/MOSRotating.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -944,11 +944,10 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
944944
gibVelocity.RadRotate(randAngle + RandomNum(0.0F, spread) + static_cast<float>(i) * goldenAngle);
945945

946946
if (gibSettingsObject.InheritsVelocity() > 0) {
947-
if (!rotatedGibOffset.IsZero()) {
948-
Vector rotationalVelocity = (rotatedGibOffset.GetPerpendicular() * m_AngularVel * gibSettingsObject.InheritsVelocity()) / c_PPM;
949-
gibVelocity += rotationalVelocity;
950-
}
951-
gibParticleClone->SetAngularVel(gibParticleClone->GetAngularVel() + m_AngularVel * gibSettingsObject.InheritsVelocity());
947+
Vector offsetFromRootParent = m_Pos - GetRootParent()->GetPos() + rotatedGibOffset;
948+
Vector rotationalVelocity = (offsetFromRootParent.GetPerpendicular() * GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsVelocity()) / c_PPM;
949+
gibVelocity += rotationalVelocity;
950+
gibParticleClone->SetAngularVel(gibParticleClone->GetAngularVel() + GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsVelocity());
952951
}
953952

954953
if (lifetime != 0) {
@@ -1009,11 +1008,10 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
10091008
}
10101009

10111010
if (gibSettingsObject.InheritsVelocity() > 0) {
1012-
if (!rotatedGibOffset.IsZero()) {
1013-
Vector rotationalVelocity = (rotatedGibOffset.GetPerpendicular() * m_AngularVel * gibSettingsObject.InheritsVelocity()) / c_PPM;
1014-
gibVelocity += rotationalVelocity;
1015-
}
1016-
gibParticleClone->SetAngularVel(gibParticleClone->GetAngularVel() + m_AngularVel * gibSettingsObject.InheritsVelocity());
1011+
Vector offsetFromRootParent = m_Pos - GetRootParent()->GetPos() + rotatedGibOffset;
1012+
Vector rotationalVelocity = (offsetFromRootParent.GetPerpendicular() * GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsVelocity()) / c_PPM;
1013+
gibVelocity += rotationalVelocity;
1014+
gibParticleClone->SetAngularVel(gibParticleClone->GetAngularVel() + GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsVelocity());
10171015
}
10181016

10191017
gibParticleClone->SetVel(gibVelocity + ((m_PrevVel + m_Vel) / 2) * gibSettingsObject.InheritsVelocity());
@@ -1480,8 +1478,8 @@ Attachable* MOSRotating::RemoveAttachable(Attachable* attachable, bool addToMova
14801478
}
14811479
RTEAssert(attachable->IsAttachedTo(this), "Tried to remove Attachable " + attachable->GetPresetNameAndUniqueID() + " from presumed parent " + GetPresetNameAndUniqueID() + ", but it had a different parent (" + (attachable->GetParent() ? attachable->GetParent()->GetPresetNameAndUniqueID() : "ERROR") + "). This should never happen!");
14821480

1483-
Vector rotationalVelocity = ((attachable->GetPos() - m_Pos).GetPerpendicular() * m_AngularVel) / c_PPM;
1484-
attachable->SetAngularVel(attachable->GetAngularVel() + m_AngularVel);
1481+
Vector rotationalVelocity = ((attachable->GetPos() - GetRootParent()->GetPos()).GetPerpendicular() * GetRootParent()->GetAngularVel()) / c_PPM;
1482+
attachable->SetAngularVel(attachable->GetAngularVel() + GetRootParent()->GetAngularVel());
14851483
attachable->SetVel(attachable->GetVel() + rotationalVelocity); // Attachables have already had their velocity updated by ApplyImpulses(), no need to add impactImpulse again
14861484

14871485
if (!m_Attachables.empty()) {

0 commit comments

Comments
 (0)