public override void UpdateOnceBeforeFrame() { base.UpdateOnceBeforeFrame(); Physics.Enabled = true; Physics.RigidBody.Activate(); Physics.RigidBody.ContactPointCallbackDelay = 0; Physics.RigidBody.ContactSoundCallbackEnabled = true; //return; if (InitialHit != null) { Physics.ApplyImpulse(InitialHit.Impulse, Physics.CenterOfMassWorld); MyPhysics.FractureImpactDetails fid = new Sandbox.Engine.Physics.MyPhysics.FractureImpactDetails(); fid.Entity = this; fid.World = Physics.HavokWorld; fid.ContactInWorld = InitialHit.Position; HkdFractureImpactDetails details = HkdFractureImpactDetails.Create(); details.SetBreakingBody(Physics.RigidBody); details.SetContactPoint(Physics.WorldToCluster(InitialHit.Position)); details.SetDestructionRadius(0.05f); details.SetBreakingImpulse(30000); details.SetParticleVelocity(InitialHit.Impulse); details.SetParticlePosition(Physics.WorldToCluster(InitialHit.Position)); details.SetParticleMass(500); fid.Details = details; MyPhysics.EnqueueDestruction(fid); } }
public void CreateSIDestruction(Vector3D worldCenter) { HkdFractureImpactDetails details = HkdFractureImpactDetails.Create(); details.SetBreakingBody(m_cubeGrid.Physics.RigidBody); details.SetContactPoint(m_cubeGrid.Physics.WorldToCluster(worldCenter)); details.SetDestructionRadius(1.5f); details.SetBreakingImpulse(Sandbox.MyDestructionConstants.STRENGTH * 10); details.SetParticleVelocity(Vector3.Zero); details.SetParticlePosition(m_cubeGrid.Physics.WorldToCluster(worldCenter)); details.SetParticleMass(10000); //details.ZeroColidingParticleVelocity(); details.Flag = details.Flag | HkdFractureImpactDetails.Flags.FLAG_DONT_RECURSE; if (m_cubeGrid.GetPhysicsBody().HavokWorld.DestructionWorld != null) { MyPhysics.FractureImpactDetails destruction = new MyPhysics.FractureImpactDetails(); destruction.Details = details; destruction.World = m_cubeGrid.GetPhysicsBody().HavokWorld; destruction.Entity = m_cubeGrid; destruction.ContactInWorld = worldCenter; MyPhysics.EnqueueDestruction(destruction); } }
private void Hammer() { var IntersectionStart = MySector.MainCamera.Position; var IntersectionDirection = MySector.MainCamera.ForwardVector; LineD line = new LineD(IntersectionStart, IntersectionStart + IntersectionDirection * 200); var m_tmpHitList = new List <MyPhysics.HitInfo>(); MyPhysics.CastRay(line.From, line.To, m_tmpHitList, MyPhysics.CollisionLayers.ObjectDetectionCollisionLayer); // Remove character hits. m_tmpHitList.RemoveAll(delegate(MyPhysics.HitInfo hit) { return(hit.HkHitInfo.GetHitEntity() == MySession.Static.ControlledEntity.Entity); }); if (m_tmpHitList.Count == 0) { return; } MyEntity closestEntity = null; MyPhysics.HitInfo closestHit = default(MyPhysics.HitInfo); foreach (var hit in m_tmpHitList) { if (hit.HkHitInfo.Body != null) { closestEntity = hit.HkHitInfo.GetHitEntity() as MyEntity; closestHit = hit; break; } } if (closestEntity == null) { return; } HkdFractureImpactDetails details = HkdFractureImpactDetails.Create(); details.SetBreakingBody(closestEntity.Physics.RigidBody); details.SetContactPoint(closestEntity.Physics.WorldToCluster(closestHit.Position)); details.SetDestructionRadius(RADIUS); details.SetBreakingImpulse(Sandbox.MyDestructionConstants.STRENGTH * 10); if (HammerForce) { details.SetParticleVelocity(-line.Direction * 20); } details.SetParticlePosition(closestEntity.Physics.WorldToCluster(closestHit.Position)); details.SetParticleMass(1000000); //details.ZeroColidingParticleVelocity(); details.Flag = details.Flag | HkdFractureImpactDetails.Flags.FLAG_DONT_RECURSE; if (closestEntity.GetPhysicsBody().HavokWorld.DestructionWorld != null) { MyPhysics.FractureImpactDetails destruction = new MyPhysics.FractureImpactDetails(); destruction.Details = details; destruction.World = closestEntity.GetPhysicsBody().HavokWorld; destruction.Entity = closestEntity; MyPhysics.EnqueueDestruction(destruction); //closestGrid.GetPhysicsBody().HavokWorld.DestructionWorld.TriggerDestruction(ref details); } //details.RemoveReference(); }