Search Unity

prevent colliders from rotating on the y axis

Discussion in '2D' started by craig4android, May 29, 2019.

  1. craig4android

    craig4android

    Joined:
    May 8, 2019
    Posts:
    124
    when I attach a 2Dcollider to a 3D mesh and rotate it on the y axis the collider doesn't rotate, which is the desired behavior for me. However if I add a child to the same transform and add a collider, the collider in the child starts to rotate around the y axis, if I rotate the parent. Is there a way to prevent 2d colliders from rotating in y. Or to make any child not rotate in y direction?
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    You could write a script that keeps the rotation the same throughout:
    Code (CSharp):
    1. public class LockRotation : MonoBehaviour
    2. {
    3.     private Quaternion _originalRotation;
    4.  
    5.     private void Awake()
    6.     {
    7.         _originalRotation = transform.rotation;
    8.     }
    9.  
    10.     private void LateUpdate()
    11.     {
    12.         transform.rotation = _originalRotation;
    13.     }
    14. }