Forum rules - please read before posting.

First-Person Player Prefab not working with ramps and stairs

edited January 2022 in Technical Q&A

Hey ya'll, I'm new to Adventure Creator and absolutely love the editor, I would've killed for something like this when I was younger! My question is about the FPS player prefab from the site. When I use it going up ramps it works fine, there's no slow down or anything, but going down ramps or stairs the prefab sort of just bounces down. I'm not really to sure how to fix it as I'm not familiar enough with programming or physics to engage it in any other way besides the inspector and nothing there has given me any results so far. Thank ya'll for your time!

EDIT: Sorry, I was certain I was in the Technical Q&A when I posted this but I must have misclicked!

Comments

  • Welcome to the community, @stealthnachos.

    To be clear: you're using the first-person player prefab from AC's Downloads page?

    What you're describing is a common problem that controllers have, and there are a number of approaches that developers take to remedy it.

    You should be able to reduce this effect by increasing the "Simulated mass" in your Player Inspector, but I shall look into this myself to see if I can provide something more robust.

  • Here's a script (StickToSlope.cs) that you can attach to your Player prefab to improve behaviour when moving down sloped surfaces:

    using UnityEngine;
    
    namespace AC
    {
    
        [RequireComponent (typeof (AC.Char))]
        public class StickToSlope : MonoBehaviour
        {
    
            [SerializeField] [Range (0f, 1f)] private float rayLength = 0.2f;
            private AC.Char character;
            private CharacterController characterController;
    
            private void Awake ()
            {
                character = GetComponent<AC.Char> ();
                characterController = GetComponent<CharacterController> ();
            }
    
            private void Update ()
            {
                if (!character.IsJumping)
                {
                    RaycastHit raycastHit = new RaycastHit ();
                    if (Physics.Raycast (transform.position + Vector3.up, -Vector3.up, out raycastHit, 1f + rayLength))
                    {
                        float distance = raycastHit.distance - 1f;
                        characterController.Move (-Vector3.up * distance);
                    }
                }
            }
    
        }
    
    }
    

    This causes the player to "snap" to the ground, so it'll work better for slopes than steps. For steps, you may wish to smoothen their colliders for smoother movement - if they make use of a Mesh Collider, you can do this by checking "Convex" in its Inspector.

  • Hey thank you so much! Yeah I am using the prefab from the site and I originally tried increasing the mass but it still jittered when it went down slopes. This method of raycasting down and measuring the normal or distance (I think thats what it’s doing at least) works great. My stairs are all set up as slopes anyway since they don’t really need a complex collider. The tool is incredibly good by the way, if you’re the person that made it I just want you to know it has been a massive help in finally making something after 10 years of trying so I can’t thank you enough!
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.