Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question How do I stop my character from spinning upon collision?

Discussion in 'Physics' started by FHISE, Jan 19, 2024.

  1. FHISE

    FHISE

    Joined:
    Jan 18, 2024
    Posts:
    3
    Video demonstrating the issue here

    I've set up my collider / rigidbody to freeze unwanted rotation, but in this case I do want rotation, I just haven't implemented it yet. But obviously I don't want the rotation to be uncontrolled like I have here.

    How do I fix this? All the suggestions I can find tell me to freeze rotation, which I have on the x and z axis, but I do want rotation on the y axis, so I can't freeze that one.
     
  2. codebiscuits

    codebiscuits

    Joined:
    Jun 16, 2020
    Posts:
    118
    Will setting a large angularDrag on the Rigidbody help (I'm assuming the Rigidbody has decent mass)? This should stop the rotation pretty quickly.
    I guess another thing could be, I'm wondering if the collision between the character and the wall is "good". Like, if you're forcing the character into the wall hard, it'll try and ping back out of the wall hard.
     
  3. FHISE

    FHISE

    Joined:
    Jan 18, 2024
    Posts:
    3
    Thanks, I increased the mass and angular drag, and also froze the y axis rotation (will rotate programatically instead). That seems to have stopped the uncontrolled spinning. But I still find that my character just stops for no reason, as if an invisible wall spawned, and I'm not sure what's going on there. That happens too with my original setup, and pressing on causes the spin. Here, it just stops - a step in the right direction, but still something wrong. Any idea how I can fix that?

    Video demonstrating the issue here
     
  4. codebiscuits

    codebiscuits

    Joined:
    Jun 16, 2020
    Posts:
    118
    A little hard to see sorry.
    I wonder if there is too much friction or linear drag and your character's getting stuck.
    Maybe the physics debugger will help, or some debug rays to show where you're applying forces or whatever.
    You could maybe try grabbing one of the free 3rd-person controllers on the asset store and comparing what they're doing:
    https://assetstore.unity.com/packag...-updates-in-new-charactercontroller-pa-196526
    https://assetstore.unity.com/packag...person-controller-basic-locomotion-free-82048 (not sure this has source)
    https://assetstore.unity.com/packages/tools/gui/item-inventory-system-45568
    My son's used all of these in various projects, they seem reasonable.