Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

【Ground Fitter (free)】- Fit your dynamic objects to ground

Discussion in 'Assets and Asset Store' started by FimpossibleCreations, Jul 20, 2018.

  1. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    You giving groundFitter quaternion y value (it's not degrees) you need put here euler degrees (this is viewed inside inspector window), so:
    Code (CSharp):
    1. fitter.RotationYAxis = lookCenter.rotation.eulerAngles.y;
     
    Last edited: Sep 18, 2019
  2. NerdIt-

    NerdIt-

    Joined:
    Oct 19, 2018
    Posts:
    24
    nvm. I found a solution. I just did this:
    Code (CSharp):
    1. fitter.RotationYAxis = lookCenter.rotation.y * 180;
    and it works fine. Don't know why it happens though.
     
  3. NerdIt-

    NerdIt-

    Joined:
    Oct 19, 2018
    Posts:
    24
    @FimpossibleGames You have been very helpful thx. Sorry that I am a noob at using these sorts of unity assets. I am just trying to get the actual fitting to work now. But like some others in this thread... it isn't working. I have read through some of the comments but I still can't find what is wrong. Here are my Ground Fitter settings:

    The plane I am testing the object on is slanted at 9 on the X-axis and is tagged as Ground. Is this correct or am I missing something?
     
  4. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    I don't think if I fully understand, but also plane shouldn't be tagged as Ground, it layer should be Ground.
     
  5. NerdIt-

    NerdIt-

    Joined:
    Oct 19, 2018
    Posts:
    24
    @FimpossibleGames
    Sorry, I meant layer not tagged. I just don't know how to get the actual fitter to work now. Absolutely nothing happens on the default settings and nothing happens on the settings that I copied from the example prefabs.
     
  6. NerdIt-

    NerdIt-

    Joined:
    Oct 19, 2018
    Posts:
    24
    The object just falls through the ground. even though it has a box collider
     
  7. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    Can you mail me scene with the problem? There can be many different cases for the issue.
     
  8. NerdIt-

    NerdIt-

    Joined:
    Oct 19, 2018
    Posts:
    24
  9. NerdIt-

    NerdIt-

    Joined:
    Oct 19, 2018
    Posts:
    24
    Just checked and the mesh for the Bear model I was using had disappeared. You need to reapply that. You will also have to reapply the Gravity script to the "@SceneManager" gameObject. That should be it.
     
  10. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    I don't know how movement of your characters will be calculated, but if you need ground fitter only to change rotation, untoggle first variable 'ChangePosition' then ground fitter will not try to glue object to the ground.
    Take a look on pink line in scene window, it's ray which will try to detect collision, your model origin center isn't foots so you can set 'RaycastHeightOffset' to zero, so ray will start from center of the model, then change 'RaycastCheckRange' to about 15 (ray will reach ground below feets of bear), because your model is very big. Then it works for me on the scene. (but bear was bouncing off the plane when I hitted play so I freezed rigidbody and moved bear over plane in scene window)
     
  11. NerdIt-

    NerdIt-

    Joined:
    Oct 19, 2018
    Posts:
    24
    It worked thx
     
  12. NerdIt-

    NerdIt-

    Joined:
    Oct 19, 2018
    Posts:
    24
    @FimpossibleGames Hi me again. Your asset worked for a bit (not accurately mind you, but that would have been my fault), but I recently watched your "Rigging a Dragon" video on youtube and tried to apply it to the bear (which I still haven't animated). It didn't work at all. I tried to follow as closely along as could with my smaller model, I ignored the animation bits just for now because I didn't animations set up yet.

    Whenever I approached a hill. The bear will automatically pull itself up to the top extremely fast and then would stick there like a magnet. How do I fix?
     
  13. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    I will send you full setup with explanation in PM soon
     
  14. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    would this work with a third person controller?
     
  15. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    Depends what you mean, there is example scene with tpp camera.
     
  16. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    i mean like can i just use the rotation without using to much of the provide movement (using the provided movement only allows my character to walk back and forwards but not sideways
     
  17. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    I also noticed by player carries on with the animation on slope areas :/
     
  18. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    I will send you soon version with possibility to move in any direction (it will be built in next ground fitter version) but I had a bit too much stuff to handle lately :(
     
  19. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    ah its okay hope you are okay :). i just need the rotation side of this asset to allow my player to walk down banks
     
  20. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    Sorry it took so long, I just added ground fitter 1.1.9 to review and should be soon on the store.
    I can't send you PM (you have limited profile) but you can send message to me if you want this version sooner ;)
     
  21. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    for some reason since the update my player wont tilt when going up and down a hill :(
     
  22. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    There was many script updates in newest version, some variables could be resetted, please check if ground layer mask is now correct for your project.


    V1.2.0 Changelog:
    - Reworked some scripts for cleaner view in code (parenting, smaller classes etc.)
    WARNING: Some variables can be resetted when you import this version
    - Upgraded precision of root motion rotation
    - Added new simplified component
    - Added scene which is using simplified component in use with Unity's CharacterController physical movement component and root motion

    * Changed variable names like:
    RotationYAxis to UpAxisRotation
    ChangePosition to GlueToGround
    YOffset to UpOffset
    delta to deltaTime
     
  23. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    check them at everything works as it should accept the tilting is no longer working
     
  24. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    My player keeps spinning back to to face its original starting position anyone know what could be causing this? also would this asset work with swimming (like a buoyancy)?
     
  25. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,443
    I tried having a snake move and fit to the ground. Which ones of your assets do I need to make this work? Or is that even possible at all? Currently the head is in the terrain, i guess because the pivot is in the center.

    s.jpg
    And is it possible to have a more natural input, i. e. pressing right should move the gameobject to it's right, not to the right side.

    Thanks for the help!
     
  26. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    You can use 'Zone Cast' to make ground detection longer for long creature like this
    (One of my tutorial with setting Zone Cast)
    but if you need all segments of snake fit to ground you would need Spine Animator
    (For Spine animator: If your snake bones structure goes straight from neck to tail end or in reversal, if your skeleton goes from center to neck and from center to tail end it will not work, also with spine animator pivot on head would help indeed, with just ground fitter it's better to keep it in center)

    Yes you can, you can do custom input script, but try pressing Q and E keys, it will move to sides.
     
    Rowlan likes this.
  27. unity_7UFP4-iCkwsgjg

    unity_7UFP4-iCkwsgjg

    Joined:
    Dec 13, 2017
    Posts:
    323
    whenever i open my project my player with the ground fitter movement wont move, i have to remove input and movement ground fitter then re-add them to get it working again any ideas what could be issue?
     
  28. ml785

    ml785

    Joined:
    Dec 20, 2018
    Posts:
    119
    Thanks so much for making this. I'm kinda a newbie, so I'm wondering - at 25 seconds in your promotional video (
    ) you can see the creature's tail going through the floor. Do you have recommendations for what would keep it above ground?
     
  29. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    When use Spine Animator tail would align to movement and not clip through floor but it's not free.
    Or use Tail Animator and apply collisions.
    Last thing you can do is rotating your tail bone (In LateUpdate() ) when creature object is rotated in x axis too much.
     
    Last edited: Apr 30, 2020
    ml785 likes this.
  30. mick129

    mick129

    Joined:
    Jun 19, 2013
    Posts:
    228
    I have downloaded your asset and it work great, I have also discovered your other tools like Optimizer and the Spine one and this is very good! Good job.

    For this tool, I have added 2 update method (the start and awake) and you might want to add them for other devs. An interesting case is that I use tools to generate procedural dungeons/villages at runtime and I use your tool to raycast every objects to the ground on "Start"

    Example: House is always 90 degree from the ground, while fences will adapt to the slope of the ground and the result work great.
     
  31. lucidtripper

    lucidtripper

    Joined:
    Aug 3, 2017
    Posts:
    28
    can I use this asset to keep my vive-tracked player on the ground? wll it stop the player going through walls? eg. player uses FINAL IK to animate their avatar - and the avatar sticks to the ground using this asset.. player is on a flat floor at home - but vr character might be walking down a hill or up some stairs...
     
  32. killerKeks26601

    killerKeks26601

    Joined:
    Jan 13, 2021
    Posts:
    31
    Hello,
    Im pretty new to Unity and coding in generell and ran into a lot of trouble aligning my Player to the ground(2D btw).
    I would really like to use your asset but it doesnt seem to work for me.
    Does it not work with 2D or am i missing something else?
     
  33. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    Hello, unfortunately it's not working with 2D stuff, but I will note this idea for the future update.
     
  34. SammmZ

    SammmZ

    Joined:
    Aug 13, 2014
    Posts:
    174
    Hey! Love your animation assets <3
    I'm having a hard time trying to integrate the GroundFitter into my NPC movement, can't manage the Y rotation properly. Here is the part responsible for the Y rotation on my NPC
    Code (CSharp):
    1.                         Quaternion currentLookAtRotation = Entity.GetLookRotation();
    2.                         Vector3 lookRotationEuler = Quaternion.LookRotation(lookAtDirection).eulerAngles;
    3.                         lookRotationEuler.x = 0;
    4.                         lookRotationEuler.z = 0;
    5.                         currentLookAtRotation = Quaternion.RotateTowards(currentLookAtRotation, Quaternion.Euler(lookRotationEuler), turnToEnemySpeed * Time.deltaTime);
    6.                         Entity.SetLookRotation(currentLookAtRotation);
    Did I understand right that instead of Entity.SetLookRotation(currentLookAtRotation); I need to pass something to the fitter.UpAxisRotation ?
     
  35. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    Hello, thanks! and yes you need to do something like fitter.UpAxisRotation = lookRotationEuler.y; and that's all
     
    SammmZ likes this.
  36. SamRock

    SamRock

    Joined:
    Sep 5, 2017
    Posts:
    250
    @FimpossibleCreations

    Thanks for the awesome assets. Love your demo videos.

    I was trying Ground Fitter for one of my monster character with 4 legs ( kind of a demon spider :D )

    From your video it seemed like the character's feet were getting aligned to the ground perfectly. But when i tried the same for my character fits the ground, but each foott just hangs in the air.
    Is my understanding of the asset wrong? Could you please guide me, basically I want each foot to touch ground like in a foot IK.

    Here is a small video of my monster character chasing the player



    Thank you again!

    I
     
  37. unity_B57BC6306274C79F026A

    unity_B57BC6306274C79F026A

    Joined:
    Apr 8, 2021
    Posts:
    12
    Dearest congratulations on your asset. I am trying to use it, specifically I would like to solve a small bug, that is the pedestrians in my app (it is a simulation of an urban environment) when they move in the navsmesh and walk in the sidewalks they walk anchored to the ground, when instead they walk on the street (ten centimeters lower) remain suspended and do not lower. Is it possible to solve with your asset?
    Thanks in advance
    Mauro
     
  38. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    Are you sure the models you want characters walk on have collider? Also the layer must fit ground fitter's layer mask in order to detect collision.
     
  39. SamRock

    SamRock

    Joined:
    Sep 5, 2017
    Posts:
    250
    Hi @FimpossibleCreations ,could you please guide me here?
     
  40. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    Sorry, I missed the message somehow.
    Well it can depend on your keyframe animation, it looks like pelvis of your walk animation don't have motion and feels like it's floating, other thing is that if you have bigger and longer model, you will notice foot disconnection more, origin of model can change it a bit too. Which video you mean? Maybe it was using Ground Fitter + Spine Animator?
     
    SamRock likes this.
  41. Justice-V18

    Justice-V18

    Joined:
    Sep 18, 2012
    Posts:
    4
    Hi @FimpossibleCreations, I tried using 'fitter.UpAxisRotation' as you mentionedd above to align the Y axis on an agent to it's movement direction. But I am getting an error stating: 'FGroundFitter_Base.UpAxisRotation' is inaccessible due to its protection level.

    I have an AI agent with the FGroundFitter component attached to it and the following script but not sure why I am getting this error:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.AI;
    5. using Unity.AI.Navigation;
    6. using FIMSpace.GroundFitter;
    7.  
    8. public class AlignToGround : MonoBehaviour
    9. {
    10.     public NavMeshAgent agent;
    11.     private FGroundFitter fitter;
    12.     public float rotationSpeed = 3f;
    13.  
    14.     void Start()
    15.     {
    16.         fitter = GetComponent<FGroundFitter>();
    17.         agent = GetComponent<NavMeshAgent>();
    18.     }
    19.  
    20.     void Update()
    21.     {
    22.         // Calculating look rotation to target point
    23.         Vector3 targetPoint = agent.nextPosition + agent.desiredVelocity;
    24.         float yRotation = Quaternion.LookRotation(new Vector3(targetPoint.x, 0f, targetPoint.z) - transform.position).eulerAngles.y;
    25.  
    26.         // Setting top down rotation in ground fitter component with smoothing (lerp)
    27.         fitter.UpAxisRotation = Mathf.LerpAngle(fitter.UpAxisRotation, yRotation, Time.deltaTime * rotationSpeed);
    28.     }
    29. }
    30.  
     
  42. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    It seems ground fitter and your script is in other assembly definition or so, I changed code to support it, check the newest update on the asset store, it should solve that ;)
     
  43. Justice-V18

    Justice-V18

    Joined:
    Sep 18, 2012
    Posts:
    4
    Yes, that was correct, they are both located in two different assembly definitions, I updated it and it managed to resolve the issue. Thank you so much for the fast response and fix.
     
  44. MisterAndersun

    MisterAndersun

    Joined:
    May 16, 2019
    Posts:
    2
    Hi FImpossible Creations. Thanks for your ground fitter tool! I am having trouble getting objects (spiders) to head towards a waypoint when they are walking on the ceiling of a cave. Everything works well as long as they are walking on the ground. I think I need to adjust the y euler angle value to account for the object being upside down but am not sure how to go about it. Any help would be greatly appreciated.

    Code (CSharp):
    1.  public struct MoveJob : IJobParallelForTransform
    2.         {
    3.             public NativeArray<RaycastHit> raycastResults;
    4.          
    5.  
    6.             public NativeArray<float3> waypointPositions;
    7.  
    8.             public NativeArray<bool> reachedTarget;
    9.             public NativeArray<quaternion> helperRotations;
    10.  
    11.             public float time;
    12.             public NativeArray<float> upAxisEuler;
    13.             public float travelSpeed;
    14.             public float fittingSpeed;
    15.  
    16.             public void Execute(int i, TransformAccess transform)
    17.             {
    18.                 transform.position = raycastResults[i].point;
    19.  
    20.                 Quaternion fromTo = Quaternion.FromToRotation(Vector3.up, raycastResults[i].normal);
    21.  
    22.                 helperRotations[i] = Quaternion.Slerp(helperRotations[i], fromTo, time * fittingSpeed);
    23.  
    24.                 float maxForwardRotation = 180f;
    25.                 float mildForwardValue = 0;
    26.                 float maxHorizontalRotation = 180f;
    27.                 float mildHorizontalValue = 0f;
    28.  
    29.                 Quaternion targetRotation = helperRotations[i];
    30.  
    31.                 targetRotation = Quaternion.Euler(Mathf.Clamp(WrapAngle(targetRotation.eulerAngles.x), -maxForwardRotation, maxForwardRotation) * (1 - mildForwardValue),
    32.                     targetRotation.eulerAngles.y,
    33.                     Mathf.Clamp(WrapAngle(targetRotation.eulerAngles.z), -maxHorizontalRotation, maxHorizontalRotation) * (1 - mildHorizontalValue));
    34.  
    35.                 Vector3 target = waypointPositions[i];
    36.                 Quaternion look = Quaternion.LookRotation(target - transform.position, -Vector3.up);
    37.                 float yEulerDif = Mathf.Abs(transform.rotation.eulerAngles.y - look.eulerAngles.y);
    38.                 float turnSpeed = yEulerDif/5;
    39.                 upAxisEuler[i] = Mathf.LerpAngle(upAxisEuler[i], look.eulerAngles.y, time * turnSpeed);
    40.  
    41.                 transform.rotation = targetRotation * Quaternion.AngleAxis(upAxisEuler[i], Vector3.up);
    42.  
    43.                 transform.position += transform.localToWorldMatrix.MultiplyVector(Vector3.forward * time * travelSpeed);
    44.  
    45.                 float distance = Vector3.Distance(transform.position, waypointPositions[i]);
    46.                 if (distance < 3f)
    47.                 {
    48.                     reachedTarget[i] = true;
    49.                 }
    50.             }
    51.  
    52.             float WrapAngle(float angle)
    53.             {
    54.                 angle %= 360;
    55.  
    56.                 if (angle > 180) return angle - 360;
    57.  
    58.                 return angle;
    59.             }
    60.         }
     
  45. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    Hello, unfortunately ground fitter logics are not supporting moving on slopes > 90 degrees.
     
  46. MisterAndersun

    MisterAndersun

    Joined:
    May 16, 2019
    Posts:
    2
    Understood. Thanks for getting back to me.
     
  47. KMDeclius

    KMDeclius

    Joined:
    Aug 12, 2019
    Posts:
    213
    Hi,
    first of all, I think the assets from @FimpossibleCreations are great. Besides this free asset, I also bought others.

    My first step here was to get [Ground Fitter] running with following configuration:
    • Unity 2021.2.13f1
    • Framerate in Edior ~120 fps (limited by other stuff)
    • NavMesh Package
    • Ground Fitter V1.2.2
    Also I'm using following hierarchy:

    RootGameObject - with
    NavMeshAgent
    and
    FGroundFitter_Demo_NavMesh.cs

    |->Child - with
    FGroundFitter

    |->TheAnimatedObject​

    (The preferred hierarchy for using it with navMeshes is not very clear to me)

    I got some issue regarding the NavMeshAgent and when using
    FGroundFitter_Demo_NavMesh.cs
    to get all the nice animation control done by the Asset: The Y-Position of the fitted Gameobject was sometimes off-it was not following the surface. It was stalling at a certain height and then sometimes jumped back to nearly the correct y. The agent though was fittet to the navMesh.

    Some debugging later:
    FGroundFitter_Demo_NavMesh.cs
    modifies the position of the transform with a value calculated from some smoothing algorithm.[EDIT] This creates wrong y-values.[/EDIT]
    I don't know if it's caused by the framerate or the Unity Version or whatever.

    I hope it's ok for the asset creator, heres the fix what worked for me:
    Replace line 110 of
    FGroundFitter_Demo_NavMesh.cs

    Code (CSharp):
    1. transform.position = newPos;
    with
    Code (CSharp):
    1. transform.position = new Vector3(newPos.x, transform.position.y, newPos.z);
    to really follow the navMesh.

    Alternatively, to follow the mesh itself,
    GlueToGround
    of
    FGroundFitter
    also works.

    I hope this helps.
    Greetings.
     
  48. SammmZ

    SammmZ

    Joined:
    Aug 13, 2014
    Posts:
    174
    While I need a very basic "rotate NPC along the slope " functionality I expected that the recently added Ground Rotator component is what I should use. I have a simple setup with the main NPC prefab (with NavMesh agent, logic, and stuff) and a child object (that are the root of my actual animated NPC). This child object is free to rotate, I can rotate it manually during the animation, so nothing is blocking the rotation. I put GroundRotator to this child object, set the root (main parent GameObject) and nothing happens. It just set rotation to 0.0.0 every frame. I tried to disable all colliders, I have defined Ground layer, I see raycast debug beams, I tweaked every setting on the component ... It's always 0.0.0 no matter what. It may sound stupid, but are we sure this component actually works? Do we have like demoscene that shows how it's working?

    EDIT. OK, I found it! Seems like the object to attach Ground Rotator must be not a simple hierarchy root of the skeleton, but an actual bone that is a part of a skinned mesh.
     
    Last edited: Nov 8, 2022
  49. TheST4R

    TheST4R

    Joined:
    Apr 22, 2019
    Posts:
    4
    How it behaves with a rootmotion based character controller?
     
  50. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    549
    There is switch on the bottom of the component to enable handling root motion and there is example scene handling root motion translation and rotation, if you already have movement character controller, you can use "FGroundRotator" component (follow the instructions in the inspector window) on the root bone of your character and it should work fine without affecting movement controller.
     
    TheST4R likes this.