Пример #1
0
        private void IKFeetStepSounds(MyEntity3DSoundEmitter walkEmitter, MySoundPair cueEnum)
        {
            var movementState = m_character.GetCurrentMovementState();

            if (movementState.GetMode() == MyCharacterMovement.Flying)
            {
                return;
            }

            if (movementState.GetSpeed() != m_lastUpdateMovementState.GetSpeed())
            {
                walkEmitter.StopSound(true);
                m_lastStepTime = 0;
            }

            int usedMinimumDelay = int.MaxValue;

            if (movementState.GetDirection() != MyCharacterMovement.NoDirection)
            {
                switch (movementState.GetSpeed())
                {
                case MyCharacterMovement.NormalSpeed:
                    usedMinimumDelay = m_stepMinimumDelayWalk;
                    break;

                case MyCharacterMovement.Fast:
                    usedMinimumDelay = m_stepMinimumDelayRun;
                    break;

                case MyCharacterMovement.VeryFast:
                    usedMinimumDelay = m_stepMinimumDelaySprint;
                    break;
                }
            }

            bool minimumDelayExceeded = false;

            minimumDelayExceeded = (MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastStepTime) >= usedMinimumDelay;
            //MyRenderProxy.DebugDrawAABB(m_character.PositionComp.WorldAABB, Color.White);

            if (minimumDelayExceeded)
            {
                int             leftAnkleBoneIndex, rightAnkleBoneIndex;
                MyCharacterBone leftAnkleBone = m_character.AnimationController != null
                    ? m_character.AnimationController.FindBone(m_character.Definition.LeftAnkleBoneName, out leftAnkleBoneIndex)
                    : null;

                MyCharacterBone rightAnkleBone = m_character.AnimationController != null
                    ? m_character.AnimationController.FindBone(m_character.Definition.RightAnkleBoneName, out rightAnkleBoneIndex)
                    : null;

                Vector3 posLeftFoot = leftAnkleBone != null
                    ? leftAnkleBone.AbsoluteTransform.Translation
                    : m_character.PositionComp.LocalAABB.Center;
                Vector3 posRightFoot = rightAnkleBone != null
                    ? rightAnkleBone.AbsoluteTransform.Translation
                    : m_character.PositionComp.LocalAABB.Center;
                float            ankleHeight;
                MyFeetIKSettings settingsIK;
                if (m_character.Definition.FeetIKSettings != null &&
                    m_character.Definition.FeetIKSettings.TryGetValue(MyCharacterMovementEnum.Standing, out settingsIK))
                {
                    ankleHeight = settingsIK.FootSize.Y;
                }
                else
                {
                    ankleHeight = DEFAULT_ANKLE_HEIGHT;
                }
                float charSpeed = 0f;
                if (m_character.AnimationController != null)
                {
                    m_character.AnimationController.Variables.GetValue(MyAnimationVariableStorageHints.StrIdSpeed, out charSpeed);
                }
                if (posLeftFoot.Y - ankleHeight < m_character.PositionComp.LocalAABB.Min.Y ||
                    posRightFoot.Y - ankleHeight < m_character.PositionComp.LocalAABB.Min.Y)
                {
                    if (charSpeed > 0.05f)
                    {
                        walkEmitter.PlaySound(cueEnum);
                    }
                    m_lastStepTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
                }
            }

            m_lastUpdateMovementState = movementState;
        }
Пример #2
0
 internal void TrySpawnWalkingParticles()
 {
     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
                     {
                         Vector3D          up       = base.Entity.PositionComp.WorldMatrix.Up;
                         Vector3D          from     = base.Entity.PositionComp.WorldMatrix.Translation + (0.2 * up);
                         MyPhysics.HitInfo?nullable = MyPhysics.CastRay(from, (base.Entity.PositionComp.WorldMatrix.Translation + (0.2 * up)) - (0.5 * up), 0x1c);
                         if (nullable != null)
                         {
                             MyVoxelPhysicsBody physics = nullable.Value.HkHitInfo.GetHitEntity().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 position = nullable.Value.Position;
                                 MyVoxelMaterialDefinition materialAt = physics.m_voxelMap.GetMaterialAt(ref position);
                                 if (materialAt != null)
                                 {
                                     MyMaterialPropertiesHelper.Static.TryCreateCollisionEffect(walk, position, (Vector3)up, ID_CHARACTER, materialAt.MaterialTypeNameHash, null);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Пример #3
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);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
        public void FindAndPlayStateSound()
        {
            m_character.Breath.Update();
            var cueEnum = SelectSound();

            var  primaryEmitter          = m_soundEmitters[(int)MySoundEmitterEnum.PrimaryState];
            var  walkEmitter             = m_soundEmitters[(int)MySoundEmitterEnum.WalkState];
            bool sameSoundAlreadyPlaying = (cueEnum.Arcade == primaryEmitter.SoundId ||
                                            (MyFakes.ENABLE_NEW_SOUNDS && cueEnum.Realistic == primaryEmitter.SoundId));

            if (primaryEmitter.Sound != null)
            {
                primaryEmitter.Sound.SetVolume(MathHelper.Clamp(m_character.Physics.LinearAcceleration.Length() / 3.0f, 0.6f, 1));
            }

            if (!sameSoundAlreadyPlaying)
            {
                bool skipIntro = cueEnum == CharacterSounds[(int)CharacterSoundsEnum.JETPACK_RUN_SOUND] || cueEnum == CharacterSounds[(int)CharacterSoundsEnum.JETPACK_IDLE_SOUND];

                if (cueEnum == CharacterSounds[(int)CharacterSoundsEnum.JETPACK_RUN_SOUND])
                {
                    if (primaryEmitter.Loop)
                    {
                        primaryEmitter.StopSound(false);
                    }
                    primaryEmitter.PlaySound(cueEnum, false, skipIntro);
                }
                else if (cueEnum == CharacterSounds[(int)CharacterSoundsEnum.JETPACK_IDLE_SOUND] && m_soundEmitters[(int)MySoundEmitterEnum.PrimaryState].SoundId == CharacterSounds[(int)CharacterSoundsEnum.JETPACK_RUN_SOUND].SoundId)
                {
                    primaryEmitter.StopSound(false);
                }
                else if (cueEnum == CharacterSounds[(int)CharacterSoundsEnum.NONE_SOUND])
                {
                    foreach (var soundEmitter in m_soundEmitters)
                    {
                        if (soundEmitter.Loop)
                        {
                            soundEmitter.StopSound(false);
                        }
                    }
                }
                else
                {
                    if (primaryEmitter.Loop)
                    {
                        primaryEmitter.StopSound(false);
                    }
                    primaryEmitter.PlaySound(cueEnum, true, skipIntro);
                }
            }
            else if (MyPerGameSettings.NonloopingCharacterFootsteps)
            {
                var movementState = m_character.GetCurrentMovementState();

                if (movementState.GetMode() == MyCharacterMovement.Flying)
                {
                    return;
                }

                if (movementState.GetSpeed() != m_lastUpdateMovementState.GetSpeed())
                {
                    walkEmitter.StopSound(true);
                }

                bool playSound = false;
                int  usedDelay = int.MaxValue;
                if (movementState.GetDirection() != MyCharacterMovement.NoDirection)
                {
                    switch (movementState.GetSpeed())
                    {
                    case MyCharacterMovement.NormalSpeed:
                        usedDelay = m_stepDelayWalk;
                        break;

                    case MyCharacterMovement.Fast:
                        usedDelay = m_stepDelayRun;
                        break;

                    case MyCharacterMovement.VeryFast:
                        usedDelay = m_stepDelaySprint;
                        break;
                    }
                }

                playSound = (MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastStepTime) >= usedDelay;
                if (playSound)
                {
                    walkEmitter.PlaySound(cueEnum);
                    m_lastStepTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
                }

                m_lastUpdateMovementState = movementState;
            }
        }