Search Unity

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:
    6,277
    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,156
    You don't need this code. Use rigidbody2d or set limit position/rotation checkboxes for rigidbody3d