Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Player is trapped in a corner....?

Discussion in 'Editor & General Support' started by grka, Jul 21, 2015.

  1. grka

    grka

    Joined:
    Jan 14, 2015
    Posts:
    80
    Hello

    I bought an asset from the store which seems to have a bug with Unity 5. In 4 everything was okay. I wrote the author an email with the bug but since months I don't get any answer if there is an update planned. So I need to fix it myself. I can walk through a room into a corner. On the way there the player seems to "jump" over something and on the way back he seems to walk against an invisible wall. I have no idea how to find out why he can't walk back. The room is build through some different modules and the invisible wall seems to be directly at the border between 2 room modules. I have made a small video to show what I mean. In the editor I can't see any reason for the problem. What is the best way to find the reason now?
    www.planetsocial.de/FN3D/game.mp4
     
  2. William_Lee_Sims

    William_Lee_Sims

    Joined:
    Oct 11, 2014
    Posts:
    40
    Have you tried turning on the wireframe mode in the Scene tab? I watched the video and I'd be curious about the geometry.
     
  3. grka

    grka

    Joined:
    Jan 14, 2015
    Posts:
    80
    Ok I made another video with the wireframe. I also tried already to delete the fork in the hand of the farmer but it didn't change something.
    www.planetsocial.de/FN3D/game2.mp4
     
  4. William_Lee_Sims

    William_Lee_Sims

    Joined:
    Oct 11, 2014
    Posts:
    40
    It's really bizarre that your character steps up the table going into the corner and doesn't do that with the chair coming out of the corner. You'd think it'd step right up.

    I can see the modular geometry, but the character doesn't look like he's quite at the edge of a module. If you remove the table and chest, can you move out? (Not that it's a solution, just another test point.)

    You said this didn't happen in Unity 4. Are you using one of the standard character controllers built into Unity or are you controlling the character yourself? If you're using one the built-in ones, you might try using the latest version in case there were changes made.
     
  5. grka

    grka

    Joined:
    Jan 14, 2015
    Posts:
    80
    I moved the table away and also made the character smaller but it seems I can't step over this thicker dark line where both room-modules hit each other. I slowly think that the reason may be the locomotion script. I tried to understand it but so far I don't. It was delivered by the author of the asset:

    The farmer has a script called LocomotionPlayer:
    Code (CSharp):
    1. /// <summary>
    2. ///
    3. /// </summary>
    4.  
    5. using UnityEngine;
    6. using System;
    7. using System.Collections;
    8.  
    9. [RequireComponent(typeof(Animator))]
    10.  
    11. //Name of class must be name of file as well
    12.  
    13. public class LocomotionPlayer : MonoBehaviour
    14. {
    15.  
    16.     public GameObject currentHorse;
    17.     public GameObject currentDoor;
    18.     public bool atDoor;
    19.     private Transform mountPoint;
    20.     protected Animator animator;
    21.     private bool _jump;//jump button press detection
    22.     private bool _getOnHorse;
    23.     public bool ridingHorse;
    24.     private float speed = 0;
    25.     private float direction = 0;
    26.     private Locomotion locomotion = null;
    27.  
    28.     // Use this for initialization
    29.     void Start ()
    30.     {
    31.         animator = GetComponent<Animator>();
    32.         locomotion = new Locomotion(animator);
    33.     }
    34.  
    35.     void Update ()
    36.     {
    37.  
    38.      
    39.         if (animator && Camera.main)
    40.         {
    41.             //Debug.Log(Camera.main.ToString());
    42.             _jump = Input.GetButton("Jump") ? true : false;//check if jump button was pressed
    43.             JoystickToEvents.Do(transform, Camera.main.transform, ref speed, ref direction);
    44.             locomotion.Do(speed, direction);
    45.         }
    46.         //DOOR CONTROL
    47.         if (Input.GetKeyDown(KeyCode.E))
    48.         {
    49.             if (atDoor && currentDoor != null)
    50.             {
    51.                 Transform newPosition = currentDoor.GetComponent<DoorControl>().teleportTo;
    52.                 Camera newCamera = currentDoor.GetComponent<DoorControl>().camToEnable;
    53.                 Camera offCamera = currentDoor.GetComponent<DoorControl>().camToDisable;
    54.                 this.transform.position = newPosition.position;
    55.                 if (newCamera != null)
    56.                 {
    57.                     newCamera.enabled = true;
    58.                  
    59.                 }
    60.                 else
    61.                 {
    62.                     return;
    63.                 }
    64.                 if (offCamera != null)
    65.                 {
    66.                     offCamera.enabled = false;
    67.                 }
    68.                 else
    69.                 {
    70.                     return;
    71.                 }
    72.             }
    73.             else
    74.             {
    75.                 return;
    76.             }
    77.         }
    78.  
    79.         Vector3 ahead = transform.forward;
    80.         Vector3 rayStart = new Vector3(this.transform.position.x, this.transform.position.y + 1f, this.transform.position.z);
    81.         Ray    ray = new Ray(rayStart, ahead);
    82.         RaycastHit hit;
    83.         if (Physics.Raycast(ray, out hit, 3f))
    84.         {
    85.             if (hit.transform.gameObject.name == ("horse"))
    86.             {
    87.                 currentHorse = hit.transform.gameObject;
    88.                 mountPoint = currentHorse.transform.Find("horseMountPoint");
    89.                 if (Input.GetKey(KeyCode.E))
    90.                 {
    91.                     this.transform.position = mountPoint.position;
    92.                     this.transform.rotation = mountPoint.rotation;
    93.                     ridingHorse = true;
    94.                     StartCoroutine(getOnHorse());
    95.                     _getOnHorse = true;
    96.                 }
    97.             }
    98.             if (hit.transform.gameObject.name == ("dog"))
    99.             {
    100.                 if (Input.GetKey(KeyCode.E))
    101.                 {
    102.                     hit.transform.gameObject.GetComponent<DogControl>().idling = false;
    103.                     hit.transform.gameObject.GetComponent<AnimalSounds>().PlaySound();
    104.                 }
    105.             }
    106.         }
    107.         if (ridingHorse)
    108.         {
    109.             if (Input.GetKey(KeyCode.F))
    110.             {
    111.                 _getOnHorse = false;
    112.                 ridingHorse = false;
    113.                 this.animator.applyRootMotion = true;
    114.                 currentHorse.GetComponent<HorseControl>().canControll = false;
    115.                 this.transform.parent = null;
    116.                 StartCoroutine(getOffHorse());
    117.             }
    118.         }
    119.     }
    120.     void FixedUpdate ()
    121.     {
    122.         animator.SetBool("Jump", _jump);
    123.         animator.SetBool("OnHorse", _getOnHorse);
    124.     }
    125.     IEnumerator getOnHorse ()
    126.     {
    127.         yield return new WaitForSeconds(1.6f);
    128.         this.animator.applyRootMotion = false;
    129.         currentHorse.GetComponent<HorseControl>().canControll = true;
    130.         this.transform.parent = currentHorse.GetComponent<HorseControl>().backBone.transform;
    131.         this.transform.position = currentHorse.GetComponent<HorseControl>().backBone.transform.position;
    132.         this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y + 0.1f, this.transform.position.z);
    133.         this.transform.rotation = currentHorse.GetComponent<HorseControl>().horseSaddle.transform.rotation;
    134.     }
    135.     IEnumerator getOffHorse ()
    136.     {
    137.         yield return new WaitForSeconds(1.6f);
    138.         this.transform.position = Vector3.Slerp(this.transform.position, mountPoint.position, 10 * Time.deltaTime);
    139.         this.transform.rotation = Quaternion.Slerp(transform.rotation, mountPoint.rotation, 10 * Time.deltaTime);
    140.     }
    141.     void OnTriggerEnter (Collider trigg)
    142.     {
    143.         if (trigg.gameObject.tag == "doorway")
    144.         {
    145.             atDoor = true;
    146.             currentDoor = trigg.gameObject;
    147.         }
    148.         else
    149.         {
    150.             //TODO: Farmer kommt nicht aus der Ecke vom Haus raus wo die Truhe ist
    151.             Debug.Log("Hit: " + trigg.gameObject.ToString());
    152.         }
    153.     }
    154.     void OnTriggerExit (Collider trigg)
    155.     {
    156.         if (trigg.gameObject.tag == "doorway")
    157.         {
    158.             atDoor = false;
    159.             currentDoor = null;
    160.         }
    161.     }
    162. }
    163.  
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class JoystickToEvents : MonoBehaviour
    5. {
    6.     public static void Do (Transform root, Transform camera, ref float speed, ref float direction)
    7.     {
    8.         Vector3 rootDirection = root.forward;
    9.         float horizontal = Input.GetAxis("Horizontal");
    10.         float vertical = Input.GetAxis("Vertical");
    11.  
    12.         Vector3 stickDirection = new Vector3(horizontal, 0, vertical);
    13.  
    14.         // Get camera rotation.  
    15.  
    16.         Vector3 CameraDirection = camera.forward;
    17.         CameraDirection.y = 0.0f; // kill Y
    18.         Quaternion referentialShift = Quaternion.FromToRotation(Vector3.forward, CameraDirection);
    19.  
    20.         // Convert joystick input in Worldspace coordinates
    21.         Vector3 moveDirection = referentialShift * stickDirection;
    22.  
    23.         Vector2 speedVec =  new Vector2(horizontal, vertical);
    24.         speed = Mathf.Clamp(speedVec.magnitude, 0, 2);
    25.  
    26.         if (speed > 0.01f) // dead zone
    27.         {
    28.             Vector3 axis = Vector3.Cross(rootDirection, moveDirection);
    29.             direction = Vector3.Angle(rootDirection, moveDirection) * (axis.y < 0 ? -0.5f : 0.5f);
    30.         }
    31.         else
    32.         {
    33.             direction = 0.0f;
    34.         }
    35.     }
    36.  
    37. }
    38.  
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Locomotion
    5. {
    6.     private Animator m_Animator = null;
    7.  
    8.     private int m_SpeedId = 0;
    9.     private int m_AgularSpeedId = 0;
    10.     private int m_DirectionId = 0;
    11.  
    12.     public float m_SpeedDampTime = 0.5f;
    13.     public float m_AnguarSpeedDampTime = 0.25f;
    14.     public float m_DirectionResponseTime = 0.1f;
    15.  
    16.     public Locomotion(Animator animator)
    17.     {
    18.         m_Animator = animator;
    19.  
    20.         m_SpeedId = Animator.StringToHash("Speed");
    21.         m_AgularSpeedId = Animator.StringToHash("AngularSpeed");
    22.         m_DirectionId = Animator.StringToHash("Direction");
    23.     }
    24.  
    25.     public void Do(float speed, float direction)
    26.     {
    27.         AnimatorStateInfo state = m_Animator.GetCurrentAnimatorStateInfo(0);
    28.  
    29.         bool inTransition = m_Animator.IsInTransition(0);
    30.         bool inIdle = state.IsName("Locomotion.Idle");
    31.         bool inTurn = state.IsName("Locomotion.TurnOnSpot") || state.IsName("Locomotion.PlantNTurnLeft") || state.IsName("Locomotion.PlantNTurnRight");
    32.         bool inWalkRun = state.IsName("Locomotion.WalkRun");
    33.  
    34.         float speedDampTime = inIdle ? 0 : m_SpeedDampTime;
    35.         float angularSpeedDampTime = inWalkRun || inTransition ? m_AnguarSpeedDampTime : 0;
    36.         float directionDampTime = inTurn || inTransition ? 1000000 : 0;
    37.  
    38.      
    39.  
    40.         float angularSpeed = direction / m_DirectionResponseTime;
    41.      
    42.         m_Animator.SetFloat(m_SpeedId, speed, speedDampTime, Time.deltaTime);
    43.         m_Animator.SetFloat(m_AgularSpeedId, angularSpeed, angularSpeedDampTime, Time.deltaTime);
    44.         m_Animator.SetFloat(m_DirectionId, direction, directionDampTime, Time.deltaTime);
    45.     }
    46.  
    47.  
    48. }
    49.  
    I understand only parts of it but in the rest of the game (outside the house) it works without problems.
     
  6. grka

    grka

    Joined:
    Jan 14, 2015
    Posts:
    80
    In the inspector my farmer looks like that:
     
  7. William_Lee_Sims

    William_Lee_Sims

    Joined:
    Oct 11, 2014
    Posts:
    40
    This is a totally wild guess that you may have tried, but if you change the StepOffset to something quite high does he still pass through? It's not a solution, but it would determine if the player is getting stuck on an edge.

    One other thing I thought of is to check that you didn't modify the corner piece from the asset (like changing it's collision type).

    Finally, is there a way to make a world with just the corner piece to see if it happens alone?
     
  8. grka

    grka

    Joined:
    Jan 14, 2015
    Posts:
    80
    I did some more investigation. I compared all locomotion scripts with the original scripts but everything is the same. I also compared all components from the farmer and the house assets they are all the same. The only difference is that I once changed the avatar of the farmer. I tried the old avatar and he can get out of the corner:
    www.planetsocial.de/FN3D/old_Avatar.mp4

    the new one can't. I recorded how I moved the house module and it seems my new avatar can't get over the modul border:
    www.planetsocial.de/FN3D/new_Avatar.mp4

    One more change was that I told the camera to follow the farmer inside the house instead of remaining in the corner. I added this feature to the old farmer project too and it didn't cause the problem with the old avatar either. I also exported the house as a prefab in the old project and used this prefab in the new one to make sure all modules and configurations are identical but it didn't fix the problem

    I also discovered that the new avatar falls through the ground when he walks on another house modul (the one in front of the fireplace)

    What could be wrong with the new avatar?
     
  9. grka

    grka

    Joined:
    Jan 14, 2015
    Posts:
    80
    ok this gets slowly on my nerves because the more I try to find the reason the more strange it becomes to me. I made a new project and imported the demo scene from the asset. Everything works fine. Then I imported me new avatare to this project and exchanged the old avatare to the new one and everything works fine.

    Then I compared both asset folders with the folders in my project. Everything is identically.

    Then I copied these 2 folders to my project and overwrote everything. When I start my own scene the problem is there again. when I start the demo scene in the subfolder everything works fine. Both scene use the same assets and the entries for the farmer and the house are identically to me. So why does the farmer behave so strange in my scene but the same asset works fine in the demo scene even though they use the same assets?
     
  10. William_Lee_Sims

    William_Lee_Sims

    Joined:
    Oct 11, 2014
    Posts:
    40
    Well... knowledge is progress. :)

    Are there colliders or triggers in other game objects with behaviour callbacks that could be changing how your farmer behaves? I really doubt this could be the problem given the similarity between the versions, but it's hard to blame the character itself after all of your discoveries. I would even consider triggers that lie outside the building near that corner.
     
  11. grka

    grka

    Joined:
    Jan 14, 2015
    Posts:
    80
    How can I find this out?
     
  12. William_Lee_Sims

    William_Lee_Sims

    Joined:
    Oct 11, 2014
    Posts:
    40
    You can click on each object near you (including outside) and see if any of them have Colliders (especially if they are just triggers). You'll then need to see if there are behaviours that check for a collision on those same game objects. I'd look for anything that might modify your character's behaviours, forces, or position.

    You'd probably know if you wrote something like that, but this asset you are using might have some scripts stopping the player. (Long shot, but it's the next thing I'd look for.)
     
  13. grka

    grka

    Joined:
    Jan 14, 2015
    Posts:
    80
    Yeah!!!! I finally found it :) I checked some gameobjects outside of the house and found one that has an invisble collider box. That box was too large and parts of it got into the indoor room!!! :) Thank you very much for your help and suggestions that helped alot :)
     
  14. William_Lee_Sims

    William_Lee_Sims

    Joined:
    Oct 11, 2014
    Posts:
    40
    Cool! I'm glad I could help.