Search Unity

character floats above ground when in game mode

Discussion in 'Scripting' started by yaramaris95, Aug 23, 2019.

  1. yaramaris95

    yaramaris95

    Joined:
    May 27, 2019
    Posts:
    20
    Hello everyone,

    so i have a problem with my self made character in unity. The character is made and animated in blender and then put into unity. Now when i put it in the scene everything is fine and both feet are on the ground, but when i press play the character floats above the terain a bit. I couldnt find a solution to this anywhere so im hopeing that you guys can help me once more.
    on ground.png of ground.png
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    I'm assuming you are using a character controller. If so, then this may be related to the skin width property. Try reducing it. However, making it too small may end up with you falling through the ground when moving at high velocities on not-flat terrain. That said, in most cases very small values are fine.
    Or you could try and move the character controller hitbox a bit higher so your feet stick out on the bottom for the same distance as the hitbox is "thick" if that makes sense.
    Also, if you are using a character controller, i believe it's not intended to use it together with a rigidbody.
     
    takeoga123 and angela314 like this.
  3. yaramaris95

    yaramaris95

    Joined:
    May 27, 2019
    Posts:
    20
    I have no idea what a character controller is:oops: maybe that is the problem. Could you maybe explain it to me or link a post/website/YouTube that explains it? I'm fairly new to unity an making games
     
  4. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    I thought you were using a CharacterController, since i assumed the green outline to be a capsule shaped hitbox. Now I see it's not even a capsule, but a cylinder, so that's my bad, sorry.
    Either way, if it changes its height from where you placed it, then some component that controlls its position is responsible for that.
    You only have 2 scripts attached, so it should be either your PlayerMovement script, or the NavMeshAgent. As a disclaimer: I have never worked with NavMeshAgents so far, but looking at the adjustable parameters, the only thing i see that may be responsible for the floating would be the base offset parameter. According to the documentation this is responsible for vertical displacement of the owning gameobject. Did you try adjusting that? Maybe even to below 0?
     
    christospac likes this.
  5. yaramaris95

    yaramaris95

    Joined:
    May 27, 2019
    Posts:
    20
    The cylinder indeed belongs to the navmeshagent. I haven't tryed to change the base offset yet. I will try that as soon as I get to my pc

    edit: that did fix the floating problem, unfortuneatly now my animations stoped working (didnt work before i changed anything but did work when i closed unity yesterday)
     
    Last edited: Aug 24, 2019
  6. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    I cant really help you on the animation problem, but if it did not work before you changed something, then it's obviously not related to the change. You say it basically worked when you closed unity yesterday, but does not work after starting today. Since things dont change between sessions, maybe you forgot to save something? Try checking if everything is still enabled and so on.
     
  7. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    487
    If anyone else comes across this problem, it has to do with the NavMesh and the size of the NavMeshAgent offset. Simply go to the Base Offset field in the NavMeshAgent and reduce it. I had to set mine to -0.06
     
  8. techtycho

    techtycho

    Joined:
    Sep 10, 2020
    Posts:
    4
    First, Check the player's collider and fix it to perfectly match the player model.
    Second, If you are using Unity terrain, The performance may be bad, Because the Unity's terrain colliders are not perfect. And it is one of the cons of using Unity's built in terrain. I would suggest modeling the terrain from Blender or any external software, And then adding a mesh collider to it, Make sure to adjust it so it suits your needs.
    Third, The problem might be in the animation, Maybe you accidently animated the players body to move upwards.
    Fourth, You can animate the player in the built in Unity animator.
    Hope that helped you fix the problem.
     
    Tyi77 and lokkyaff like this.
  9. rjiang1218

    rjiang1218

    Joined:
    Feb 4, 2022
    Posts:
    1
    life saver!!!!!!!!!!!
     
  10. The11thAlchemist

    The11thAlchemist

    Joined:
    Aug 10, 2020
    Posts:
    30
    Although changing the base offset does work, I found it caused problems with my animation system (currently using MxM) because a base offset causes the navmesh agent to constantly try to reach that position (even when a destination is not set. Instead, look at your animation settings. In the animation clip preview window change the model to the one you are using and you will see that your character is floating above the ground. Then change the animation offset so your character is touching the ground