public static void TriggerDestruction(float destructionImpact, MyPhysicsBody body, Vector3D position, Vector3 normal, float maxDestructionRadius) { if (body.BreakableBody != null) { float collidingMass = body.Mass;// == 0 ? Mass : body.Mass; //fall on voxel float destructionRadius = Math.Min(destructionImpact / 8000, maxDestructionRadius); float destructionImpulse = MyDestructionConstants.STRENGTH + destructionImpact / 10000; float expandVelocity = Math.Min(destructionImpact / 10000, 3); MyPhysics.FractureImpactDetails destruction; HkdFractureImpactDetails details; details = HkdFractureImpactDetails.Create(); details.SetBreakingBody(body.RigidBody); details.SetContactPoint(body.WorldToCluster(position)); details.SetDestructionRadius(destructionRadius); details.SetBreakingImpulse(destructionImpulse); details.SetParticleExpandVelocity(expandVelocity); //details.SetParticleVelocity(contactVelocity); details.SetParticlePosition(body.WorldToCluster(position - normal * 0.25f)); details.SetParticleMass(10000000);//collidingMass); details.ZeroCollidingParticleVelocity(); details.Flag = details.Flag | HkdFractureImpactDetails.Flags.FLAG_DONT_RECURSE | HkdFractureImpactDetails.Flags.FLAG_TRIGGERED_DESTRUCTION; destruction = new MyPhysics.FractureImpactDetails(); destruction.Details = details; destruction.World = body.HavokWorld; destruction.ContactInWorld = position; destruction.Entity = (MyEntity)body.Entity; MyPhysics.EnqueueDestruction(destruction); } }
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 static unsafe void TriggerDestruction(float destructionImpact, MyPhysicsBody body, Vector3D position, Vector3 normal, float maxDestructionRadius) { if (body.BreakableBody != null) { float mass = body.Mass; HkdFractureImpactDetails details2 = HkdFractureImpactDetails.Create(); details2.SetBreakingBody(body.RigidBody); details2.SetContactPoint((Vector3)body.WorldToCluster(position)); details2.SetDestructionRadius(Math.Min(destructionImpact / 8000f, maxDestructionRadius)); details2.SetBreakingImpulse(MyDestructionConstants.STRENGTH + (destructionImpact / 10000f)); details2.SetParticleExpandVelocity(Math.Min((float)(destructionImpact / 10000f), (float)3f)); details2.SetParticlePosition((Vector3)body.WorldToCluster(position - (normal * 0.25f))); details2.SetParticleMass(1E+07f); details2.ZeroCollidingParticleVelocity(); HkdFractureImpactDetails *detailsPtr1 = (HkdFractureImpactDetails *)ref details2; detailsPtr1.Flag = (details2.Flag | HkdFractureImpactDetails.Flags.FLAG_DONT_RECURSE) | HkdFractureImpactDetails.Flags.FLAG_TRIGGERED_DESTRUCTION; MyPhysics.FractureImpactDetails details = new MyPhysics.FractureImpactDetails { Details = details2, World = body.HavokWorld, ContactInWorld = position, Entity = (VRage.Game.Entity.MyEntity)body.Entity }; MyPhysics.EnqueueDestruction(details); } }
public static unsafe void TriggerDestruction(HkWorld world, HkRigidBody body, Vector3 havokPosition, float radius = 0.0005f) { HkdFractureImpactDetails details = HkdFractureImpactDetails.Create(); details.SetBreakingBody(body); details.SetContactPoint(havokPosition); details.SetDestructionRadius(radius); details.SetBreakingImpulse(MyDestructionConstants.STRENGTH * 10f); HkdFractureImpactDetails *detailsPtr1 = (HkdFractureImpactDetails *)ref details; detailsPtr1.Flag = details.Flag | HkdFractureImpactDetails.Flags.FLAG_DONT_RECURSE; MyPhysics.FractureImpactDetails details2 = new MyPhysics.FractureImpactDetails { Details = details, World = world }; MyPhysics.EnqueueDestruction(details2); }
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(); }