public MyGridContactInfo(ref HkContactPointEvent evnt, MyCubeGrid grid)
 {
     Event             = evnt;
     ContactPosition   = grid.Physics.ClusterToWorld(evnt.ContactPoint.Position);
     m_currentEntity   = grid;
     m_collidingEntity = Event.GetOtherEntity(grid) as MyEntity;
     m_currentBlock    = null;
     m_otherBlock      = null;
     ImpulseMultiplier = 1;
 }
 public MyGridContactInfo(ref HkContactPointEvent evnt, MyCubeGrid grid)
 {
     Event = evnt;
     ContactPosition = grid.Physics.ClusterToWorld(evnt.ContactPoint.Position); 
     m_currentEntity = grid;
     m_collidingEntity = Event.GetOtherEntity(grid) as MyEntity;
     m_currentBlock = null;
     m_otherBlock = null;
     ImpulseMultiplier = 1;
 }
Example #3
0
 private void RigidBody_ContactPointCallback(ref HkContactPointEvent value)
 {
     if (Sync.IsServer)
     {
         VRage.ModAPI.IMyEntity otherEntity = value.GetOtherEntity(this);
         if (otherEntity is MyFloatingObject)
         {
             this.m_entitiesToTake.Add(otherEntity as MyFloatingObject);
             MySandboxGame.Static.Invoke(() => base.NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME, "MyCollector::NeedsUpdate");
         }
     }
 }
        //isnt used
        void RigidBody_ContactPointCallback(ref HkContactPointEvent value)
        {
            if (!Sync.IsServer)
            {
                return;
            }
            var entity = value.GetOtherEntity(this);

            if (entity is MyFloatingObject)
            {
                m_entitiesToTake.Add(entity as MyFloatingObject);
                NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            }
        }
Example #5
0
 //isnt used
 void RigidBody_ContactPointCallback(ref HkContactPointEvent value)
 {
     if (!Sync.IsServer)
         return;
     var entity = value.GetOtherEntity(this);
     if (entity is MyFloatingObject)
     {
         m_entitiesToTake.Add(entity as MyFloatingObject);
         NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
     }
 }
Example #6
0
        internal void TrySpawnWalkingParticles(ref HkContactPointEvent value)
        {
            if (!MyFakes.ENABLE_WALKING_PARTICLES)
            {
                return;
            }

            var oldCheckTime = m_lastWalkParticleCheckTime;

            m_lastWalkParticleCheckTime   = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            m_walkParticleSpawnCounterMs -= m_lastWalkParticleCheckTime - oldCheckTime;
            if (m_walkParticleSpawnCounterMs > 0)
            {
                return;
            }

            var naturalGravityMultiplier = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(Entity.PositionComp.WorldMatrix.Translation);

            if (naturalGravityMultiplier <= 0f)
            {
                m_walkParticleSpawnCounterMs = m_walkParticleGravityDelay;
                return;
            }

            var character = Entity as MyCharacter;

            if (character.JetpackComp != null && character.JetpackComp.Running)
            {
                m_walkParticleSpawnCounterMs = m_walkParticleJetpackOffDelay;
                return;
            }

            var currentMovementState = character.GetCurrentMovementState();

            if (currentMovementState.GetDirection() == MyCharacterMovement.NoDirection || currentMovementState == MyCharacterMovementEnum.Falling)
            {
                m_walkParticleSpawnCounterMs = m_walkParticleDefaultDelay;
                return;
            }

            var otherPhysicsBody = value.GetOtherEntity(character).Physics as MyVoxelPhysicsBody;        //value.Base.BodyA.UserObject == character.Physics ? value.Base.BodyB.UserObject : value.Base.BodyA.UserObject)) as MyVoxelPhysicsBody;

            if (otherPhysicsBody == null)
            {
                return;
            }

            MyStringId movementType;

            const int walkParticleWalkDelay   = 500;
            const int walkParticleRunDelay    = 275;
            const int walkParticleSprintDelay = 250;

            switch (currentMovementState.GetSpeed())
            {
            case MyCharacterMovement.NormalSpeed:
                movementType = MyMaterialPropertiesHelper.CollisionType.Walk;
                m_walkParticleSpawnCounterMs = walkParticleWalkDelay;
                break;

            case MyCharacterMovement.Fast:
                movementType = MyMaterialPropertiesHelper.CollisionType.Run;
                m_walkParticleSpawnCounterMs = walkParticleRunDelay;
                break;

            case MyCharacterMovement.VeryFast:
                movementType = MyMaterialPropertiesHelper.CollisionType.Sprint;
                m_walkParticleSpawnCounterMs = walkParticleSprintDelay;
                break;

            default:
                movementType = MyMaterialPropertiesHelper.CollisionType.Walk;
                m_walkParticleSpawnCounterMs = m_walkParticleDefaultDelay;
                break;
            }

            var spawnPosition = otherPhysicsBody.ClusterToWorld(value.ContactPoint.Position);

            MyVoxelMaterialDefinition voxelMaterialDefinition = otherPhysicsBody.m_voxelMap.GetMaterialAt(ref spawnPosition);

            if (voxelMaterialDefinition == null)
            {
                return;
            }

            MyMaterialPropertiesHelper.Static.TryCreateCollisionEffect(
                movementType,
                spawnPosition,
                value.ContactPoint.Normal,
                m_characterMaterial,
                MyStringHash.GetOrCompute(voxelMaterialDefinition.MaterialTypeName));
        }
	    internal void TrySpawnWalkingParticles(ref HkContactPointEvent value)
	    {
		    if (!MyFakes.ENABLE_WALKING_PARTICLES)
			    return;
            
		    var oldCheckTime = m_lastWalkParticleCheckTime;
		    m_lastWalkParticleCheckTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
		    m_walkParticleSpawnCounterMs -= m_lastWalkParticleCheckTime - oldCheckTime;
		    if (m_walkParticleSpawnCounterMs > 0)
			    return;

			var naturalGravityMultiplier = MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(Entity.PositionComp.WorldMatrix.Translation);
		    if (naturalGravityMultiplier <= 0f)
		    {
			    m_walkParticleSpawnCounterMs = m_walkParticleGravityDelay;
			    return;
		    }

		    var character = Entity as MyCharacter;
		    if (character.JetpackComp != null && character.JetpackComp.Running)
		    {
			    m_walkParticleSpawnCounterMs = m_walkParticleJetpackOffDelay;
			    return;
		    }

		    var currentMovementState = character.GetCurrentMovementState();
		    if (currentMovementState.GetDirection() == MyCharacterMovement.NoDirection || currentMovementState == MyCharacterMovementEnum.Falling)
		    {
			    m_walkParticleSpawnCounterMs = m_walkParticleDefaultDelay;
			    return;
		    }

		    var otherPhysicsBody = value.GetOtherEntity(character).Physics as MyVoxelPhysicsBody;//value.Base.BodyA.UserObject == character.Physics ? value.Base.BodyB.UserObject : value.Base.BodyA.UserObject)) as MyVoxelPhysicsBody;
		    if (otherPhysicsBody == null)
			    return;
	       
			MyStringId movementType;

		    const int walkParticleWalkDelay = 500;
			const int walkParticleRunDelay = 275;
			const int walkParticleSprintDelay = 250;
		    switch (currentMovementState.GetSpeed())
		    {
			    case MyCharacterMovement.NormalSpeed:
				    movementType = MyMaterialPropertiesHelper.CollisionType.Walk;
				    m_walkParticleSpawnCounterMs = walkParticleWalkDelay;
				    break;
				case MyCharacterMovement.Fast:
					movementType = MyMaterialPropertiesHelper.CollisionType.Run;
				    m_walkParticleSpawnCounterMs = walkParticleRunDelay;
				    break;
				case MyCharacterMovement.VeryFast:
					movementType = MyMaterialPropertiesHelper.CollisionType.Sprint;
				    m_walkParticleSpawnCounterMs = walkParticleSprintDelay;
				    break;
				default:
				    movementType = MyMaterialPropertiesHelper.CollisionType.Walk;
				    m_walkParticleSpawnCounterMs = m_walkParticleDefaultDelay;
				    break;

		    }

            var spawnPosition = otherPhysicsBody.ClusterToWorld(value.ContactPoint.Position);

            MyVoxelMaterialDefinition voxelMaterialDefinition = otherPhysicsBody.m_voxelMap.GetMaterialAt(ref spawnPosition);
		    if (voxelMaterialDefinition == null)
			    return;

		    MyMaterialPropertiesHelper.Static.TryCreateCollisionEffect(
				movementType,
				spawnPosition,
				value.ContactPoint.Normal,
				m_characterMaterial,
				MyStringHash.GetOrCompute(voxelMaterialDefinition.MaterialTypeName));
	    }
Example #8
0
 internal void TrySpawnWalkingParticles(ref HkContactPointEvent value)
 {
     if (MyFakes.ENABLE_WALKING_PARTICLES)
     {
         int lastWalkParticleCheckTime = this.m_lastWalkParticleCheckTime;
         this.m_lastWalkParticleCheckTime   = MySandboxGame.TotalGamePlayTimeInMilliseconds;
         this.m_walkParticleSpawnCounterMs -= this.m_lastWalkParticleCheckTime - lastWalkParticleCheckTime;
         if (this.m_walkParticleSpawnCounterMs <= 0)
         {
             if (MyGravityProviderSystem.CalculateHighestNaturalGravityMultiplierInPoint(base.Entity.PositionComp.WorldMatrix.Translation) <= 0f)
             {
                 this.m_walkParticleSpawnCounterMs = 0x2710;
             }
             else
             {
                 MyCharacter entity = base.Entity as MyCharacter;
                 if (entity.JetpackRunning)
                 {
                     this.m_walkParticleSpawnCounterMs = 0x7d0;
                 }
                 else
                 {
                     MyCharacterMovementEnum currentMovementState = entity.GetCurrentMovementState();
                     if ((currentMovementState.GetDirection() == 0) || (currentMovementState == MyCharacterMovementEnum.Falling))
                     {
                         this.m_walkParticleSpawnCounterMs = 0x3e8;
                     }
                     else
                     {
                         MyVoxelPhysicsBody physics = value.GetOtherEntity(entity).Physics as MyVoxelPhysicsBody;
                         if (physics != null)
                         {
                             MyStringId walk;
                             ushort     speed = currentMovementState.GetSpeed();
                             if (speed == 0)
                             {
                                 walk = MyMaterialPropertiesHelper.CollisionType.Walk;
                                 this.m_walkParticleSpawnCounterMs = 500;
                             }
                             else if (speed == 0x400)
                             {
                                 walk = MyMaterialPropertiesHelper.CollisionType.Run;
                                 this.m_walkParticleSpawnCounterMs = 0x113;
                             }
                             else if (speed != 0x800)
                             {
                                 walk = MyMaterialPropertiesHelper.CollisionType.Walk;
                                 this.m_walkParticleSpawnCounterMs = 0x3e8;
                             }
                             else
                             {
                                 walk = MyMaterialPropertiesHelper.CollisionType.Sprint;
                                 this.m_walkParticleSpawnCounterMs = 250;
                             }
                             Vector3D worldPosition = physics.ClusterToWorld(value.ContactPoint.Position);
                             MyVoxelMaterialDefinition materialAt = physics.m_voxelMap.GetMaterialAt(ref worldPosition);
                             if (materialAt != null)
                             {
                                 MyMaterialPropertiesHelper.Static.TryCreateCollisionEffect(walk, worldPosition, value.ContactPoint.Normal, ID_CHARACTER, materialAt.MaterialTypeNameHash, null);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #9
0
        void RigidBody_ContactPointCallback(ref HkContactPointEvent value)
        {
            ProfilerShort.Begin("Grid Contact counter");
            ProfilerShort.End();

            var otherEntity = value.GetOtherEntity(m_grid);
            var otherPhysicsBody = value.GetPhysicsBody(0);
            var thisEntity = m_grid;
            if (otherEntity == null || thisEntity == null)
                return;

            //DA used to stop appliyng force when there is planet/ship collisions to  increase performance after ship crashes on planet
            if ((Math.Abs(value.SeparatingVelocity) < 0.3f) && (otherEntity is MyTrees || otherEntity is MyVoxelPhysics))
            {
                return;
            }

            MyGridContactInfo info = new MyGridContactInfo(ref value, m_grid);

            var myBody = RigidBody;// value.Base.BodyA.GetEntity() == m_grid.Components ? value.Base.BodyA : value.Base.BodyB;

            if (info.CollidingEntity is Sandbox.Game.Entities.Character.MyCharacter || info.CollidingEntity.MarkedForClose)
                return;

            if (MyFakes.LANDING_GEAR_IGNORE_DAMAGE_CONTACTS && MyCubeGridGroups.Static.NoContactDamage.HasSameGroupAndIsGrid(otherEntity, thisEntity))
                return;

            ProfilerShort.Begin("Grid contact point callback");
            bool hitVoxel = info.CollidingEntity is MyVoxelMap || info.CollidingEntity is MyVoxelPhysics;

            if(hitVoxel && m_grid.Render != null) {
                m_grid.Render.ResetLastVoxelContactTimer();
            }

            bool doSparks = MyPerGameSettings.EnableCollisionSparksEffect && (info.CollidingEntity is MyCubeGrid || hitVoxel);

            // According to Petr, WasUsed does not work everytime
            //if (value.ContactProperties.WasUsed)
            {
                // Handle callbacks here
                info.HandleEvents();
            }

            if(MyDebugDrawSettings.DEBUG_DRAW_FRICTION)
            {
                var pos = ClusterToWorld(value.ContactPoint.Position);
                var vel = -GetVelocityAtPoint(pos);
                vel *= 0.1f;
                var fn = Math.Abs(Gravity.Dot(value.ContactPoint.Normal) * value.ContactProperties.Friction);
                if (vel.Length() > 0.5f)
                {
                    vel.Normalize();
                    MyRenderProxy.DebugDrawArrow3D(pos, pos + fn * vel, Color.Gray, Color.Gray, false);
                }
            }

            if (doSparks && Math.Abs(value.SeparatingVelocity) > 2.0f && value.ContactProperties.WasUsed && !m_lastContacts.ContainsKey(value.ContactPointId) && info.EnableParticles)
            {
                ProfilerShort.Begin("AddCollisionEffect");
                m_lastContacts[value.ContactPointId] = MySandboxGame.TotalGamePlayTimeInMilliseconds;
                AddCollisionEffect(info.ContactPosition, value.ContactPoint.Normal);
                ProfilerShort.End();
            }

            ProfilerShort.Begin("Dust");
            bool doDust = MyPerGameSettings.EnableCollisionSparksEffect && hitVoxel;
            float force = Math.Abs(value.SeparatingVelocity * (Mass / 100000));
            if (doDust && force > 0.25f && info.EnableParticles)
            {
                float scale = MathHelper.Clamp(force / 10.0f, 0.2f, 4.0f);
                AddDustEffect(info.ContactPosition, scale);
            }
            ProfilerShort.End();
            // Large dynamic ships colliding with floating objects
            // When low separating velocity or deformation performed, disable contact point
            // Floating object will still collide with kinematic part of ship and won't push it
            if (m_grid.GridSizeEnum == MyCubeSize.Large && !myBody.IsFixedOrKeyframed && info.CollidingEntity is MyFloatingObject && (Math.Abs(value.SeparatingVelocity) < 0.2f))
            {
                var prop = value.ContactProperties;
                prop.IsDisabled = true;
            }

            ProfilerShort.End();
        }
Example #10
0
        void RigidBody_ContactPointCallback(ref HkContactPointEvent value)
        {
            ProfilerShort.Begin("Grid Contact counter");
            ProfilerShort.End();

            var otherEntity = value.GetOtherEntity(m_grid);
            var thisEntity = m_grid;
            if (otherEntity == null || thisEntity == null)
                return;

            //DA used to stop appliyng force when there is planet/ship collisions to  increase performance after ship crashes on planet
            if ((Math.Abs(value.SeparatingVelocity) < 0.3f) && (otherEntity is MyTrees || otherEntity is MyVoxelPhysics))
            {
                return;
            }

            MyGridContactInfo info = new MyGridContactInfo(ref value, m_grid);

            var myBody = RigidBody;// value.Base.BodyA.GetEntity() == m_grid.Components ? value.Base.BodyA : value.Base.BodyB;

            // CH: DEBUG


            if (info.CollidingEntity is Sandbox.Game.Entities.Character.MyCharacter || info.CollidingEntity.MarkedForClose)
                return;

            if (MyFakes.LANDING_GEAR_IGNORE_DAMAGE_CONTACTS && MyCubeGridGroups.Static.NoContactDamage.HasSameGroupAndIsGrid(otherEntity, thisEntity))
                return;

            ProfilerShort.Begin("Grid contact point callback");
            bool doSparks = MyPerGameSettings.EnableCollisionSparksEffect && (info.CollidingEntity is MyCubeGrid || info.CollidingEntity is MyVoxelMap);

            // According to Petr, WasUsed does not work everytime
            //if (value.ContactProperties.WasUsed)
            {
                // Handle callbacks here
                info.HandleEvents();
            }

            bool deformationPerformed = false;

            if (Sync.IsServer && value.ContactProperties.ImpulseApplied > MyGridShape.BreakImpulse && info.CollidingEntity != null && info.EnableDeformation && m_grid.BlocksDestructionEnabled)
            {
                float deformation = value.SeparatingVelocity;
                if (info.RubberDeformation)
                {
                    deformation /= 5;
                }

                HkBreakOffPointInfo breakInfo = CreateBreakOffPoint(value, info.ContactPosition, MyGridShape.BreakImpulse);
                PerformDeformation(ref breakInfo, false, value.SeparatingVelocity, otherEntity as MyEntity);
                deformationPerformed = true;
            }
            else if (doSparks && value.SeparatingVelocity > 2.0f && value.ContactProperties.WasUsed && !m_lastContacts.ContainsKey(value.ContactPointId) && info.EnableParticles)
            {
                m_lastContacts[value.ContactPointId] = MySandboxGame.TotalGamePlayTimeInMilliseconds;
                AddCollisionEffect(info.ContactPosition, value.ContactPoint.Normal);
            }

            // Large dynamic ships colliding with floating objects
            // When low separating velocity or deformation performed, disable contact point
            // Floating object will still collide with kinematic part of ship and won't push it
            if (m_grid.GridSizeEnum == MyCubeSize.Large && !myBody.IsFixedOrKeyframed && info.CollidingEntity is MyFloatingObject && (Math.Abs(value.SeparatingVelocity) < 0.2f || deformationPerformed))
            {
                var prop = value.ContactProperties;
                prop.IsDisabled = true;
            }

            ProfilerShort.End();
        }