Search Unity

Movement script problems

Discussion in 'Editor & General Support' started by iwobrzostowski, Apr 1, 2021.

  1. iwobrzostowski

    iwobrzostowski

    Joined:
    Mar 30, 2021
    Posts:
    7
    So 2 days ago i started programing in unity. It was my first time programing ever btw. i decided to do 2d game. And i was really strugeling with movement script. And i am still strugling can somebody please help me?
    When i have all this rigedbody stuff ON it fells and it is ok, but when i add movement scripts the rigedobody and this movement script don't work. I don't know where the problem can be... i don't think it's a script beasause i downloaded it from internet and i think its ok (I tried to write my own but i didn't work i don't know why). So can somebody help me please?
     
    Last edited: Apr 1, 2021
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    No one can help you with your movement script if you don't want to post the script.

    But note that there are 3 major categories of movement in Unity, and you can't mix them unless you know exactly what you're doing. If you are mixing them, that could be the source of your problem.

    So the 3 categories are movement via the Transform directly, physics based movement with a rigidbody, and using the built in CharacterController.

    If you're doing movement using the Transform, that basically teleports the object each frame. Small teleports will look like smooth movement still. You either need to use no rigidbody or have the rigidbody set to Kinematic mode, so forces don't affect it.

    If you're doing movement with a rigidbody, you can add forces, manage the velocity directly (though you still need to be careful there), or use rigidbody.MovePosition. You should not doing movement with the transform unless you're explicitly going for a teleport effect.

    The CharacterController is sort of its own thing. You need to use its own movement methods, you shouldn't manipulate the transform directly (I think it actually teleports it back if you try anyway), and don't use a rigidbody with it.

    So just make sure you've picked 1 kind of movement for your object, and don't try to mix them. If you picked up a random movement script somewhere, there is only a 1 out of 3 chance you picked the right one :p So good luck!
     
  3. iwobrzostowski

    iwobrzostowski

    Joined:
    Mar 30, 2021
    Posts:
    7
    Ok, so i think it can be something wrong with my menu code, beacause when i add a new scene and i don't have main menu scene it will work and i can move character but when i add this menu it stop working so maybe in this folder with my menu is somethng wrong. I don't think it's code beacuase this code is very simple. Do you know what can cause this problem? i will create a new menu beacuase it stoped working and i will see is this is a poblem. Oh and thanks for a tip :)
     
  4. iwobrzostowski

    iwobrzostowski

    Joined:
    Mar 30, 2021
    Posts:
    7
    scripts:
     

    Attached Files:

  5. iwobrzostowski

    iwobrzostowski

    Joined:
    Mar 30, 2021
    Posts:
    7
    oh and i did new project and added this scripts nad it don't work so, well i don't knoe what can it be.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,744
    It will NEVER just be code. There is ALWAYS important work to do in the scene as well. Start from a full working tutorial, don't just grab some random script off the internet. That will NEVER work.

    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    How to understand compiler and other errors and even fix them yourself:

    https://forum.unity.com/threads/ass...3-syntax-error-expected.1039702/#post-6730855

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    Also, consider this:
     
    Joe-Censored likes this.
  7. iwobrzostowski

    iwobrzostowski

    Joined:
    Mar 30, 2021
    Posts:
    7
    I watched many of tutorials and did step by step, but it wasn't working.