Exemplo n.º 1
0
        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.ObjectDetectionCollisionLayer);
            // Remove character hits.
            m_tmpHitList.RemoveAll(delegate(MyPhysics.HitInfo hit)
            {
                return(hit.HkHitInfo.Body.GetEntity() == MySession.ControlledEntity.Entity);
            });

            if (m_tmpHitList.Count == 0)
            {
                return;
            }

            MyEntity closestGrid = null;

            MyPhysics.HitInfo closestHit = default(MyPhysics.HitInfo);

            foreach (var hit in m_tmpHitList)
            {
                if (hit.HkHitInfo.Body != null)
                {
                    closestGrid = hit.HkHitInfo.Body.GetEntity() as MyEntity;
                    closestHit  = hit;
                    break;
                }
            }
            if (closestGrid == null)
            {
                return;
            }
            HkdFractureImpactDetails details = HkdFractureImpactDetails.Create();

            details.SetBreakingBody(closestGrid.Physics.RigidBody);
            details.SetContactPoint(closestGrid.Physics.WorldToCluster(closestHit.Position));
            details.SetDestructionRadius(RADIUS);
            details.SetBreakingImpulse(Sandbox.MyDestructionConstants.STRENGTH * 10);
            if (HammerForce)
            {
                details.SetParticleVelocity(-line.Direction * 20);
            }
            details.SetParticlePosition(closestGrid.Physics.WorldToCluster(closestHit.Position));
            details.SetParticleMass(1000000);
            //details.ZeroColidingParticleVelocity();
            details.Flag = details.Flag | HkdFractureImpactDetails.Flags.FLAG_DONT_RECURSE;
            if (closestGrid.Physics.HavokWorld.DestructionWorld != null)
            {
                MyPhysics.FractureImpactDetails destruction = new MyPhysics.FractureImpactDetails();
                destruction.Details = details;
                destruction.World   = closestGrid.Physics.HavokWorld;
                MyPhysics.EnqueueDestruction(destruction);
                //closestGrid.Physics.HavokWorld.DestructionWorld.TriggerDestruction(ref details);
            }
            //details.RemoveReference();
        }