Forum rules - please read before posting.

Better grounded detection?

edited March 4 in Technical Q&A

My first-person player is currently not playing footstep sounds when walking on uneven terrain. The grounded bool seems to turn off on the slightest slope. Any way to fix this?

https://streamable.com/p4x3q9

AC Version 1.79.3
Unity Version 2022.3.18f1

Comments

  • The ground detection calculation depends on the components the character has attached - are you relying on a Character Controller or RIgidbody + Capsule Collider pairing?

    Also are you assigning footstep sounds in the Player component, or the dedicated Footstep Sounds component?

  • I'm using a Character Controller with the footstep sounds component

  • Open up AC's Char script and replace the line:

    return _characterController.isGrounded;
    

    Replace it with:

    if (_characterController.isGrounded) return true;
    return Physics.CheckCapsule (Transform.position + (_characterController.bounds.size.x / 2f * UpDirection), Transform.position + (_characterController.bounds.size.x / 4f * UpDirection), _characterController.bounds.size.y * 0.45f, groundCheckLayerMask);
    

    Does that resolve it?

  • I think the detection is a little better, still missing some step sounds. Also now the character has difficulty jumping while moving.

  • Was the jumping/movement better originally? If so, best to revert back and use a different grounding script to handle FootstepSounds.

    First, open up FootstepSounds and look for the PlayFootstep function (around line 114). Just inside the function, copy/paste:

    if (!enabled) return;
    

    (I'll make the same change in the next update)

    You can then use a custom script to detect the ground, and then enable/disable the FootstepSounds component as needed. Something along these lines, but you can replace IsGrounded with your own function as necessary:

    using UnityEngine;
    public class FootstepSoundsGrounded : MonoBehaviour
    {
    
        public AC.FootstepSounds footstepSounds;
    
        void Update ()
        {
            footstepSounds.enabled = IsGrounded ();
        }
    
        bool IsGrounded ()
        {
            return Physics.Raycast (transform.position, -Vector3.up, 0.1f);
        }
    }
    
  • Yup, that works a lot better now.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.