예제 #1
0
        public void PlayRelevantSounds()
        {
            if (SoundTimeout > 0)
            {
                SoundTimeout -= TheRegion.Delta;
                return;
            }
            Location vel = GetVelocity();

            if (vel.LengthSquared() < 0.2)
            {
                return;
            }
            Material      mat   = TheRegion.GetBlockMaterial(GetPosition() + new Location(0, 0, -0.05f));
            MaterialSound sound = mat.Sound();

            if (sound == MaterialSound.NONE)
            {
                return;
            }
            double velLen = vel.Length();

            new DefaultSoundPacketIn()
            {
                TheClient = TheClient
            }.PlayDefaultBlockSound(GetPosition(), sound, 1f, 0.14f * (float)velLen);
            TheClient.Particles.Steps(GetPosition(), mat, GetVelocity(), (float)velLen);
            SoundTimeout = (Utilities.UtilRandom.NextDouble() * 0.2 + 1.0) / velLen;
        }
예제 #2
0
    void Update()
    {
        Ray mainR = new Ray(transform.position, (Listener.transform.position - transform.position));

        Debug.DrawRay(transform.position, (Listener.transform.position - transform.position), Color.green);
        RaycastHit occlusion;

        if (Vector3.Distance(Listener.transform.position, transform.position) <= SoundDistance)
        {
            MainSound.volume = Volume;
            if (Physics.Raycast(mainR, out occlusion))
            {
                oclussed = occlusion.collider.gameObject.GetComponent <MaterialSound>();
                if (oclussed)
                {
                    WallFX.cutoffFrequency   = System.Convert.ToInt32(oclussed.SMaterial()[0]);
                    WallFX.lowpassResonanceQ = System.Convert.ToInt32(oclussed.SMaterial()[1]);
                }
                else
                {
                    WallFX.cutoffFrequency = (22000);
                }
            }
            else
            {
                WallFX.cutoffFrequency = (22000);
            }
        }
        else
        {
            MainSound.volume = 0;
        }
    }
예제 #3
0
        // TODO: Move to a manager class rather than this packet class!
        public void PlayDefaultBlockSound(Location pos, MaterialSound sound, float pitchmod, float volumemod)
        {
            float pitch  = (float)(Utilities.UtilRandom.NextDouble() * 0.1 + 1.0 - 0.05);
            float volume = (float)Math.Min((Utilities.UtilRandom.NextDouble() * 0.1 + 1.0 - 0.1) * volumemod, 1.0);

            // TODO: registry of some form?
            switch (sound)
            {
            case MaterialSound.GRASS:
            case MaterialSound.SAND:
            case MaterialSound.LEAVES:
            case MaterialSound.WOOD:
            case MaterialSound.METAL:
            case MaterialSound.DIRT:
            case MaterialSound.STONE:
            case MaterialSound.SNOW:
            case MaterialSound.GLASS:
            case MaterialSound.CLAY:
            case MaterialSound.LIQUID:
            case MaterialSound.SLIME:
                // TODO: Don't manually search the sound list every time!
                TheClient.Sounds.Play(TheClient.Sounds.GetSound("sfx/steps/humanoid/" + sound.ToString().ToLowerFast() + (Utilities.UtilRandom.Next(4) + 1)), false, pos, pitch, volume);
                break;

            default:
                return;
            }
        }
예제 #4
0
 void Events_ContactCreated(EntityCollidable sender, Collidable other, CollidablePairHandler pair, ContactData contact)
 {
     if (TheRegion.GlobalTickTimeLocal - lastSoundTime < soundmaxrate)
     {
         return;
     }
     lastSoundTime = TheRegion.GlobalTickTimeLocal;
     if (other is FullChunkObject)
     {
         ((ConvexFCOPairHandler)pair).ContactInfo(/*contact.Id*/ 0, out ContactInformation info);
         float vellen = (float)(Math.Abs(info.RelativeVelocity.X) + Math.Abs(info.RelativeVelocity.Y) + Math.Abs(info.RelativeVelocity.Z));
         float mod    = vellen / 5;
         if (mod > 2)
         {
             mod = 2;
         }
         Location      block = new Location(contact.Position - contact.Normal * 0.01f);
         BlockInternal bi    = TheRegion.GetBlockInternal(block);
         MaterialSound sound = ((Material)bi.BlockMaterial).Sound();
         if (sound != MaterialSound.NONE)
         {
             new DefaultSoundPacketIn()
             {
                 TheClient = TheClient
             }.PlayDefaultBlockSound(block, sound, mod, 0.5f * mod);
         }
         MaterialSound sound2 = Mat.Sound();
         if (sound2 != MaterialSound.NONE)
         {
             new DefaultSoundPacketIn()
             {
                 TheClient = TheClient
             }.PlayDefaultBlockSound(block, sound2, mod, 0.5f * mod);
         }
     }
     else if (other is EntityCollidable)
     {
         BEPUphysics.Entities.Entity e        = ((EntityCollidable)other).Entity;
         BEPUutilities.Vector3       velocity = BEPUutilities.Vector3.Zero;
         if (e != null)
         {
             velocity = e.LinearVelocity;
         }
         BEPUutilities.Vector3 relvel = Body.LinearVelocity - velocity;
         float vellen = (float)(Math.Abs(relvel.X) + Math.Abs(relvel.Y) + Math.Abs(relvel.Z));
         float mod    = vellen / 5;
         if (mod > 2)
         {
             mod = 2;
         }
         MaterialSound sound = Mat.Sound();
         if (sound != MaterialSound.NONE)
         {
             new DefaultSoundPacketIn()
             {
                 TheClient = TheClient
             }.PlayDefaultBlockSound(new Location(contact.Position), sound, mod, 0.5f * mod);
         }
     }
 }
예제 #5
0
    private FootstepSoundEntry GetEntry(MaterialSound sound)
    {
        FootstepSoundEntry entry = sounds[(int)sound];

        if (entry.sound != sound)
        {
            Debug.LogError("Incorrect footstep entry!");
        }
        return(entry);
    }
예제 #6
0
    void FixedUpdate()
    {
        GroundCheck();
        bool             underWater       = false;
        PhysicsComponent physicsComponent = GetComponent <PhysicsComponent>();

        if (physicsComponent != null)
        {
            underWater = physicsComponent.underWater;
        }

        Vector2 input = new Vector2
        {
            x = CrossPlatformInputManager.GetAxis("Horizontal"),
            y = CrossPlatformInputManager.GetAxis("Vertical")
        };

        if (Mathf.Abs(input.x) > float.Epsilon || Mathf.Abs(input.y) > float.Epsilon)
        {
            float maxSpeed = (grounded && !underWater) ? walkSpeed : fallMoveSpeed;
            // always move along the camera forward as it is the direction that it being aimed at
            Vector3 desiredMove = Quaternion.AngleAxis(cam.transform.rotation.eulerAngles.y, Vector3.up)
                                  * new Vector3(input.x, 0, input.y);
            desiredMove  = Vector3.ProjectOnPlane(desiredMove, groundContactNormal).normalized;
            desiredMove *= input.magnitude * maxSpeed;
            if (rigidBody.velocity.sqrMagnitude < (maxSpeed * maxSpeed))
            {
                // TODO: scale by time??
                rigidBody.AddForce(desiredMove * SlopeMultiplier(), ForceMode.Impulse);
            }
        }

        if (grounded || underWater)
        {
            rigidBody.drag = 5f;

            if (jump)
            {
                rigidBody.drag     = 0f;
                rigidBody.velocity = new Vector3(rigidBody.velocity.x, 0f, rigidBody.velocity.z);
                rigidBody.AddForce(new Vector3(0f, underWater ? swimForce : jumpForce, 0f), ForceMode.Impulse);
                jumping = true;
            }
        }
        else
        {
            rigidBody.drag = 0f;
            if (previouslyGrounded && !jumping)
            {
                StickToGroundHelper();
            }
        }

        // footstep sounds...
        if (underWater)
        {
            footstepSound = MaterialSound.SWIM;
        }
        if ((grounded || underWater) && jump)
        {
            PlayFootstep();
            footstepDistance = 0;
        }
        else if ((!previouslyGrounded && grounded && !underWater) ||
                 (!previouslyUnderWater && underWater))
        {
            // landed
            StartCoroutine(LandSoundCoroutine());
            footstepDistance = 0;
        }
        else if (grounded || underWater)
        {
            Vector3 velocity = rigidBody.velocity;
            velocity.y        = 0;
            footstepDistance += velocity.magnitude * Time.fixedDeltaTime;
            if (footstepDistance > footstepStride)
            {
                footstepDistance -= footstepStride;
                PlayFootstep();
            }
        }

        jump = false;
        previouslyUnderWater = underWater;
    }
예제 #7
0
    /// sphere cast down just beyond the bottom of the capsule to see if the capsule is colliding round the bottom
    private void GroundCheck()
    {
        previouslyGrounded = grounded;
        if (disableGroundCheck)
        {
            disableGroundCheck = false;
            grounded           = false;
            jumping            = true;
        }

        RaycastHit hitInfo;

        if (Physics.SphereCast(transform.position, capsule.radius * (1.0f - shellOffset), Vector3.down, out hitInfo,
                               ((capsule.height / 2f) - capsule.radius) + groundCheckDistance, Physics.AllLayers, QueryTriggerInteraction.Ignore))
        {
            grounded            = true;
            groundContactNormal = hitInfo.normal;
            // move with moving object
            Vector3 move = Vector3.zero;
            foreach (MotionComponent motionComponent in hitInfo.transform.GetComponents <MotionComponent>())
            {
                if (motionComponent.enabled)
                {
                    move += motionComponent.GetTranslateFixed();
                    Vector3 relPos = transform.position - motionComponent.transform.position;
                    move += (motionComponent.GetRotateFixed() * relPos) - relPos;
                }
            }
            move.y = 0;
            if (move != Vector3.zero)
            {
                rigidBody.MovePosition(rigidBody.position + move);
            }

            // determine footstep sound
            if (hitInfo.collider.gameObject.tag == "Voxel")
            {
                var   voxelComponent = hitInfo.collider.GetComponent <VoxelComponent>();
                Voxel voxel;
                int   faceI;
                if (voxelComponent.GetSubstance() != null)
                {
                    // substances use convex hulls which don't have submeshes
                    // so just use the top face of the voxel
                    voxel = voxelComponent.GetSingleBlock();
                    faceI = 3;
                }
                else
                {
                    int hitVertexI = TouchListener.GetRaycastHitVertexIndex(hitInfo);
                    voxelComponent.GetVoxelFaceForVertex(hitVertexI, out voxel, out faceI);
                }
                footstepSound = voxel.faces[faceI].GetSound();
            }
            else
            {
                Renderer hitRender = hitInfo.collider.GetComponent <Renderer>();
                if (hitRender != null)
                {
                    // regular .material has (Instance) suffix
                    footstepSound = ResourcesDirectory.GetMaterialSound(hitRender.sharedMaterial);
                }
                else
                {
                    footstepSound = MaterialSound.GENERIC;
                }
            }
        }
        else
        {
            grounded            = false;
            groundContactNormal = Vector3.up;
        }
        if (!previouslyGrounded && grounded && jumping)
        {
            jumping = false;
        }
    }
예제 #8
0
    public void PlayRightFoot(MaterialSound sound)
    {
        FootstepSoundEntry entry = GetEntry(sound);

        PlayRandomFromArray(entry.right, entry.volume);
    }