Skip to content

Commit dbe58bb

Browse files
authored
Merge pull request #149 from cortex-command-community/gibsinheritrotationalvel
Gibs and detached Attachables inherit rotational velocity from parent
2 parents b3f626c + c432d78 commit dbe58bb

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ 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 and detached Attachables now inherit the parent's angular velocity, as well as velocity derived from the angular velocity of the parent MO and their offset from the parent's centre. On gibs, this is scaled by `InheritsVel`.
87+
8688
</details>
8789

8890
<details><summary><b>Fixed</b></summary>

Source/Entities/MOSRotating.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,14 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
942942
gibParticleClone->SetHFlipped(m_HFlipped);
943943
Vector gibVelocity(radius * scale + minVelocity, 0);
944944
gibVelocity.RadRotate(randAngle + RandomNum(0.0F, spread) + static_cast<float>(i) * goldenAngle);
945+
946+
if (gibSettingsObject.InheritsVelocity() > 0) {
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());
951+
}
952+
945953
if (lifetime != 0) {
946954
gibParticleClone->SetLifetime(std::max(static_cast<int>(static_cast<float>(lifetime) * (1.0F - lifeVariation * ((radius / maxRadius) * 0.75F + RandomNormalNum() * 0.25F))), 1));
947955
}
@@ -998,7 +1006,16 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
9981006
} else {
9991007
gibVelocity.RadRotate(gibSpread * RandomNormalNum());
10001008
}
1009+
1010+
if (gibSettingsObject.InheritsVelocity() > 0) {
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());
1015+
}
1016+
10011017
gibParticleClone->SetVel(gibVelocity + ((m_PrevVel + m_Vel) / 2) * gibSettingsObject.InheritsVelocity());
1018+
10021019
if (movableObjectToIgnore) {
10031020
gibParticleClone->SetWhichMOToNotHit(movableObjectToIgnore);
10041021
}
@@ -1019,6 +1036,10 @@ void MOSRotating::RemoveAttachablesWhenGibbing(const Vector& impactImpulse, Mova
10191036
RTEAssert(attachable, "Broken Attachable when Gibbing!");
10201037

10211038
if (RandomNum() < attachable->GetGibWithParentChance() || attachable->GetGibWhenRemovedFromParent()) {
1039+
float attachableGibBlastStrength = (attachable->GetParentGibBlastStrengthMultiplier() * m_GibBlastStrength) / (1 + attachable->GetMass());
1040+
attachable->SetAngularVel((attachable->GetAngularVel() * 0.5F) + (attachable->GetAngularVel() * 0.5F * attachableGibBlastStrength * RandomNormalNum()));
1041+
Vector gibBlastVel = Vector(attachable->GetParentOffset()).SetMagnitude(attachableGibBlastStrength * 0.5F + (attachableGibBlastStrength * RandomNum()));
1042+
attachable->SetVel(attachable->GetVel() + gibBlastVel); // Attachables have already had their velocity updated by ApplyImpulses(), no need to add impactImpulse again
10221043
attachable->GibThis();
10231044
continue;
10241045
}
@@ -1027,7 +1048,7 @@ void MOSRotating::RemoveAttachablesWhenGibbing(const Vector& impactImpulse, Mova
10271048
float attachableGibBlastStrength = (attachable->GetParentGibBlastStrengthMultiplier() * m_GibBlastStrength) / (1 + attachable->GetMass());
10281049
attachable->SetAngularVel((attachable->GetAngularVel() * 0.5F) + (attachable->GetAngularVel() * 0.5F * attachableGibBlastStrength * RandomNormalNum()));
10291050
Vector gibBlastVel = Vector(attachable->GetParentOffset()).SetMagnitude(attachableGibBlastStrength * 0.5F + (attachableGibBlastStrength * RandomNum()));
1030-
attachable->SetVel(m_Vel + gibBlastVel); // Attachables have already had their velocity updated by ApplyImpulses(), no need to add impactImpulse again
1051+
attachable->SetVel(attachable->GetVel() + gibBlastVel); // Attachables have already had their velocity updated by ApplyImpulses(), no need to add impactImpulse again
10311052

10321053
if (movableObjectToIgnore) {
10331054
attachable->SetWhichMOToNotHit(movableObjectToIgnore);
@@ -1457,6 +1478,10 @@ Attachable* MOSRotating::RemoveAttachable(Attachable* attachable, bool addToMova
14571478
}
14581479
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!");
14591480

1481+
Vector rotationalVelocity = ((attachable->GetPos() - GetRootParent()->GetPos()).GetPerpendicular() * GetRootParent()->GetAngularVel()) / c_PPM;
1482+
attachable->SetAngularVel(attachable->GetAngularVel() + GetRootParent()->GetAngularVel());
1483+
attachable->SetVel(attachable->GetVel() + rotationalVelocity); // Attachables have already had their velocity updated by ApplyImpulses(), no need to add impactImpulse again
1484+
14601485
if (!m_Attachables.empty()) {
14611486
m_Attachables.remove(attachable);
14621487
}

0 commit comments

Comments
 (0)