Search Unity

Question Grounding Player at Start

Discussion in 'Physics' started by m_daniel26, May 5, 2023.

  1. m_daniel26

    m_daniel26

    Joined:
    Feb 7, 2023
    Posts:
    66
    Sorry if this isn't the right thread for this question - I'm very new to Unity and the forums here, so please feel free to redirect me if this would be better posted somewhere else.

    Working in version 2021.3.20f1.

    At the start of the game, no matter what Y point I set my FPS character to, it always starts off with the player "landing" into the level as if they had jumped - which with my landing SFX starts the game off with a thump and a grunt, which is not exactly how I want it to begin. I found a similar thread suggesting to lowering the skin width of the controller, which I tried, but that didn't make any difference. Also have tried playing around with "isGrounded" and "isPreviouslyGrounded" setting each to true/false in the Awake function, but no difference there either.

    It's a relatively minor annoyance, and one I could probably learn to live with, but I know from games I've played that there must be a way around it, and probably an easy one at that if I weren't such a noob, lol.
     
  2. Mangonels

    Mangonels

    Joined:
    May 8, 2018
    Posts:
    20
    Random ideas, since you haven't shared any code:

    - Make sure you are not playing the fall SFX's with PlayOnAwake toggled to true in your AudioSource.
    - Try using the debugger, if you're not used to it already, I recommend forcefully practicing it, or looking for tutorials on how to use it.

    If you're using VS (Visual Studio), you can set a breakpoint and slowly find out what is going on at the start of your game, and what is triggering those sounds. Place breakpoints on whatever method triggers the sound, you can even open the stack trace window, this is a window in VS that can tell you previous methods where called until reaching the line where you put your breakpoint.
     
  3. m_daniel26

    m_daniel26

    Joined:
    Feb 7, 2023
    Posts:
    66
    Confirmed that PlayOnAwake is toggled off - tried your breaking points suggestion, but that didn't yield any results, other than that if I break point the LandingSound code it won't play at all (obviously, lol).

    Another note: I'm currently using FMOD as my audio controller, but I was having this same issue before I switched to FMOD and was using the built-in Unity audio player.

    The full code for my FPS controller is a bit extensive, but here's the Awake, Update, HandleJump, and PlayLandSound functions, which I'm guessing are the parts I need to focus on (annotations are //commented):

    Code (CSharp):
    1. void Awake()
    2.     {
    3.         instance = this;
    4.  
    5.         playerCamera = GetComponentInChildren<Camera>();
    6.         characterController = GetComponent<CharacterController>();
    7.         defaultYPos = playerCamera.transform.localPosition.y;
    8.         defaultFOV = playerCamera.fieldOfView;
    9.         currentHealth = 100;
    10.         currentStamina = 100;
    11.         Cursor.lockState = CursorLockMode.Locked;
    12.         Cursor.visible = false;
    13.         m_PreviouslyGrounded = false;
    14. //I've toggled m_PreviouslyGrounded to both false and true, but no result either way.
    15.    }
    16.      
    17. void Update()
    18.     {
    19.         if (CanMove)
    20.         {
    21.             HandleMovementInput();
    22.             HandleMouseLook();
    23.  
    24.             if(canJump)
    25.                 HandleJump();
    26.  
    27.             if (canCrouch)
    28.                 HandleCrouch();
    29.  
    30.             if (canUseHeadbob)
    31.                 HandleHeadbob();
    32.  
    33.             if (canZoom)
    34.                 HandleZoom();
    35.  
    36.             if (useFootsteps)
    37.                 Handle_Footsteps();
    38.  
    39.             if (canInteract)
    40.             {
    41.                 HandleInteractionCheck();
    42.                 HandleInteractionInput();
    43.             }
    44.  
    45.             if (useStamina)
    46.                 HandleStamina();
    47.  
    48.             ApplyFinalMovements();
    49.            }
    50.          }
    51.      
    52. private void HandleJump()
    53.     {
    54.         if (ShouldJump)
    55.         {
    56.             moveDirection.y = jumpForce;
    57.             PlayJumpSound();
    58.          }
    59.  
    60.         if (!m_PreviouslyGrounded && characterController.isGrounded)
    61.         {
    62.             PlayLandingSound();
    63.         }
    64.         m_PreviouslyGrounded = characterController.isGrounded;
    65.     }
    66.  //I've toggled  putting the last line "m_PreviouslyGrounded = characterController.isGrounded;" in and out of the If Statement Brackets, but that also had no effect.
    67.  
    68. private void PlayLandingSound()
    69.     {
    70.         if (Physics.Raycast(playerCamera.transform.position, Vector3.down, out RaycastHit hit, 3))
    71.         {
    72.             switch (hit.collider.tag)
    73.             {
    74.                     case "Footsteps/Wood":
    75.                     FMODUnity.RuntimeManager.PlayOneShot("event:/Player/Footsteps/Land/WoodLand");
    76.                     break;
    77.                     case "Footsteps/Metal":
    78.                     FMODUnity.RuntimeManager.PlayOneShot("event:/Player/Footsteps/Land/MetalLand");
    79.                     break;
    80.                     case "Footsteps/Carpet":
    81.                     FMODUnity.RuntimeManager.PlayOneShot("event:/Player/Footsteps/Land/CarpetLand");
    82.                     break;
    83.                     case "Footsteps/Tile":
    84.                     FMODUnity.RuntimeManager.PlayOneShot("event:/Player/Footsteps/Land/TileLand");
    85.                    break;
    86.                     case "Footsteps/Concrete":
    87.                     FMODUnity.RuntimeManager.PlayOneShot("event:/Player/Footsteps/Land/ConcreteLand");
    88.                     break;
    89.                 case "Footsteps/VentDuct":
    90.                     FMODUnity.RuntimeManager.PlayOneShot("event:/Player/Footsteps/Land/VentDuctLand");
    91.                     break;
    92.                default:
    93.                     FMODUnity.RuntimeManager.PlayOneShot("event:/Player/Footsteps/Land/ConcreteLand");
    94.                     break;
    95.             }
    96.             NextStep = StepCycle + .5f;
    97.         }
    98.     }
    99.     }
     
  4. m_daniel26

    m_daniel26

    Joined:
    Feb 7, 2023
    Posts:
    66
    The same thing happens when I use the Standard Assets FPS controller, which is why I thought it might be a common Unity setting thing (like the PlayOnAwake toggle) that I was missing.
     
    Last edited: May 7, 2023