Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Coding Error for restricting 3d objects to 2d behavior

Discussion in 'Scripting' started by kristenmg, Aug 2, 2019.

  1. kristenmg

    kristenmg

    Joined:
    Jul 23, 2019
    Posts:
    10
    Hi guys,

    I created a rope in unity that works in 3d (following this thread: https://forum.unity.com/threads/working-2d-rope-concept-for-sidscrolling-games-for-free.76721/ )

    but the code that is supposed to restrict the rope so that it responds in the 2d environment is making unity very unhappy with me.
    1. //prevents the object from moving and rotating in a way unfit for 2D

    2. function FixedUpdate () {
    3. transform.localPosition.z = 0;
    4. transform.eulerAngles.x = 0;
    5. transform.eulerAngles.y = 0;
    6. }
    Also, please note that I have absolutely no knowledge about coding, so though this might be a simple fix please explain it to me as if you were talking to a five-year-old. This is all i ask. thank you
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    8,771
    The thread you linked is from 8 years ago back before Unity had added a lot of 2D functionality, and the code is in UnityScript (pseudo JavaScript), not C#. UnityScript is no longer supported in the most recent versions of Unity.

    Can you give more information of what you're trying to do?
     
  3. kristenmg

    kristenmg

    Joined:
    Jul 23, 2019
    Posts:
    10
    I was trying to make a rope and have my player climb onto it like in this video


    In the description, it gave a couple of links to threads of how to do it, and I was following them but they weren't working. Thank you for telling me why. I was going mad
     
  4. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,736
    You don't need this code. Use rigidbody2d or set limit position/rotation checkboxes for rigidbody3d
     
unityunity