10 #ifdef ENABLE_DESTRUCTION
19 return m_DestructibleParent.GetCurrentFractalVariant().GetFragmentIndexIsAnchor(
m_iIndex);
47 return m_DestructibleParent;
54 m_DestructibleParent = destructibleParent;
59 Resource resource = Resource.Load(assetPath);
60 VObject asset = resource.GetResource().ToVObject();
62 m_DestructibleParent.GetOwner().AddChild(
this, -1);
64 Physics phys = Physics.CreateStatic(
this, -1);
66 SCR_PhysicsHelper.RemapInteractionLayer(phys, EPhysicsLayerDefs.Dynamic, EPhysicsLayerDefs.Static);
71 override void EOnContact(IEntity owner, IEntity other, Contact contact)
76 if (!m_DestructibleParent)
79 if (RplSession.Mode() == RplMode.Client)
89 Physics physics = owner.GetPhysics();
90 if ((!physics || !physics.IsDynamic()) && other && other.GetPhysics())
91 physics = other.GetPhysics();
98 float relativeForce = 0;
99 if (physics.IsDynamic())
100 relativeForce = contact.Impulse / physics.GetMass();
102 if (relativeForce < m_DestructibleParent.m_fRelativeContactForceThresholdMinimum)
105 float damage = relativeForce * m_DestructibleParent.m_fForceToDamageScale;
107 IEntity otherParent =
null;
109 otherParent = other.GetParent();
112 vector relativeVelocityBefore = contact.VelocityBefore2 - contact.VelocityBefore1;
114 outMat[0] = contact.Position;
115 outMat[1] = relativeVelocityBefore.Normalized();
116 outMat[2] = contact.Normal;
119 OnDamage(damage,
EDamageType.KINETIC, other, outMat, other, otherParent,
string.Empty, contact.GetRelativeNormalVelocityAfter() - contact.GetRelativeNormalVelocityBefore());
125 physics = owner.GetPhysics();
130 physics.SetInteractionLayer(EPhysicsLayerDefs.VehicleCast);
133 if (!physics.IsDynamic())
135 auto otherPhysics = other.GetPhysics();
136 if (otherPhysics && otherPhysics.IsDynamic())
138 vector relativeVelocityAfter = contact.VelocityAfter2 - contact.VelocityAfter1;
139 otherPhysics.SetVelocity((relativeVelocityAfter - relativeVelocityBefore) * -1 + otherPhysics.GetVelocity());
146 override void EOnFrame(IEntity owner,
float timeSlice)
153 override void OnDamage(
float damage,
EDamageType type, IEntity pHitEntity, inout vector outMat[3], IEntity damageSource, notnull
Instigator instigator,
int colliderID,
float speed)
155 if (!m_DestructibleParent)
158 if (damage < m_DestructibleParent.m_fDamageThresholdMinimum)
161 if (RplSession.Mode() == RplMode.Client)
165 if (damage >= m_DestructibleParent.m_fDamageThresholdMaximum)
167 m_DestructibleParent.OnDamage(damage,
type, pHitEntity, outMat, damageSource, damageSourceParent, colliderID, speed);
180 m_DestructibleParent.OnFragmentDestroyed(
this,
type, damage, outMat[0], outMat[1]);
185 void QueueDestroy(
EDamageType damageType,
float damage, vector hitPosition, vector hitDirection,
bool doParticleFX =
true)
188 SCR_DestructionCommon.PlayParticleEffect_FractionDestruction(
this, m_DestructibleParent.m_ParticleDestroyFragment, damageType, hitPosition, hitDirection);
192 debrisSettings.Spawn(
this, m_DestructibleParent.GetOwner().GetPhysics(), damage, hitDirection);
194 m_DestructibleParent.GetOwner().RemoveChild(
this);
195 SetEventMask(EntityEvent.FRAME);
201 SetEventMask(EntityEvent.CONTACT);