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

Player get stuck in collider

Discussion in 'Scripting' started by Harpush, Jul 9, 2014.

  1. Harpush

    Harpush

    Joined:
    Jul 2, 2014
    Posts:
    1
    So i am making a game that in a certain point the box collider needs to be scaled to another size.
    the problem is that sometimes the scale happens when my player stands in the planned collider (after the scale), which gives the result of the player being stuck inside.

    I tried a lot of methods to try and detect whether the player is inside the collider or not and if he is inside, to disable that collider allowing him to get out and once he is out to enable it again.

    Up until now, none worked. I tried doing it through RayCast and by knowing how many times it touched a collider along the way from the player and the collider's center and I tried through logic, assuming that if the player is inside the collider, so the distance from the center to the player is smaller than the box's size/2 (its a box - a square).

    Any help please? Once i solve that problem the game is almost ready to go in terms of scripting.
     
  2. Arunraj

    Arunraj

    Joined:
    Jul 4, 2012
    Posts:
    21
    hello, change your code design like, Scale the collider after you have the crossed the collider to be scaled.
    use update() to control the player, LateUpdate() to handle the collider scaling

    General Execution Order for unity

    Happy Coding :)