Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Unity Who rummages, why I put speed.x then it goes like z although right now it costs y, but it goe

Discussion in 'Scripting' started by danil2272002, Dec 11, 2019.

  1. danil2272002

    danil2272002

    Joined:
    Dec 11, 2019
    Posts:
    18
    Someone, why put speed.x then it goes like z although right now it costs y, but it goes along the x axis?

    Open Body Class: MonoBehaviour
    {
    public swimming speed = 5f;
    private swimming = 0f;
    new private rigid body Rigidbody2D;

    // Start is called before the first frame update
    void Start ()
    {
    Hardbody = GetComponent ();
    }

    // Update is called once per frame
    void Update ()
    {
    motion = Input.GetAxis ("Horizontal");
    hardbody.velocity = new Vector2 (movement speed *, solidbody.velocity.y);
    }
    }
    coming down to earth
     
  2. AlexN2805

    AlexN2805

    Joined:
    Nov 27, 2019
    Posts:
    33
    I don't understand this question.... at all.
     
    Joe-Censored likes this.
  3. danil2272002

    danil2272002

    Joined:
    Dec 11, 2019
    Posts:
    18
    why we use rigidbody.velocity.y instead rigidbody.velocity.x for run?
     
  4. danil2272002

    danil2272002

    Joined:
    Dec 11, 2019
    Posts:
    18
    you understand my question?
     
  5. AlexN2805

    AlexN2805

    Joined:
    Nov 27, 2019
    Posts:
    33
    When you set velocity.y, you set the speed of the object along the y-axis. Same goes for x and z-axis.
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,748
    This might be the least comprehensible post I've seen on these forums.
     
    Joe-Censored likes this.
  7. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Rummages? Who?
    Likely not, since they just stated otherwise.

    And this code would not compile, there is no movement variable, and * at the end of the first param is incorrect syntax.

    hardbody.velocity = new Vector2 (movement speed *, solidbody.velocity.y);
     
  8. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I'm guessing the poster ran all the code through a translator instead of just his/her question. Unless the float type has actually been renamed to "swimming" officially. Hardbody is probably supposed to be Rigidbody, etc.
     
    angrypenguin and StarManta like this.
  9. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,748
    That makes this post make a LOT more sense.
     
  10. danil2272002

    danil2272002

    Joined:
    Dec 11, 2019
    Posts:
    18
    I bad understand English, but now i write without translate i just russian, my qustion such.
    Why we use rigidbody.velocity = new Vector2(movement * speed, rigidbody.velocity.y instead igidbody.velocity = new Vector2(movement * speed, rigidbody.velocity.x so that run
     
  11. danil2272002

    danil2272002

    Joined:
    Dec 11, 2019
    Posts:
    18
    I bad understand English, but now i write without translate i just russian, my qustion such.
    Why we use rigidbody.velocity = new Vector2(movement * speed, rigidbody.velocity.y instead igidbody.velocity = new Vector2(movement * speed, rigidbody.velocity.x so that run
     
    OZAV likes this.
  12. danil2272002

    danil2272002

    Joined:
    Dec 11, 2019
    Posts:
    18
    strange, when i put rigidbody.velocity.y then he go on x-axis

    sorry for mistakes my English is very bad , i just russian
     
    Last edited: Dec 14, 2019
    OZAV likes this.
  13. OZAV

    OZAV

    Joined:
    Aug 9, 2013
    Posts:
    293
    In general, the best is to use physics properties of rigidbody, to apply force (or timed translate or rotate) a game object that rigidbody is attached to, for such purposes. Does your object have any other (sub) parts in the prefab with the scripts on it, that cause you this effect ? so ... check that first, and if you don't mind sharing a secret (that particular script here) people on the forum like to help and can definitely write you some better version of it, so you can use it later to learn more, improve on it as well and what not. P.S. Putin has a lot more of better photos, update it before you get shipped to Siberia (just a joke) :). RDA-AlienMoon-Harold.JPG
     
    Last edited: Dec 15, 2019
  14. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,386
    is your object oriented so that y is up and x is pointing to right? is your object's rotation (0,0,0)?
     
    OZAV likes this.
  15. danil2272002

    danil2272002

    Joined:
    Dec 11, 2019
    Posts:
    18
    and what you say
    about Siberia, i'm live beside with Siberia
    there not fun
     
  16. danil2272002

    danil2272002

    Joined:
    Dec 11, 2019
    Posts:
    18
    yes
     
    Last edited: Dec 14, 2019
  17. danil2272002

    danil2272002

    Joined:
    Dec 11, 2019
    Posts:
    18
    Да кстати, я код через переводчик пропустил, не спрашивай зачем, сори что приходится переводить мои слова=)
     
  18. OZAV

    OZAV

    Joined:
    Aug 9, 2013
    Posts:
    293
    As some people don't get it, It's just a joke, for living next to Siberia you will definitely have a good sense of humor - anyways, keep us updated on the problem if we can help further, it sounds that it need to be checked if there is an issue of game object being rotated by the game object, instead of by rigid body, or if there are sub objects in the prefab doing that wrong effect, so you need to check that first, before any further code excavations. Your code concept is not bad, but be careful declaring stuff in #C, and than if properly declared - go using the declarations further down the script and what not, as you know - all the wrong things in #C - start in the header declarations (despare ye not - if you have done this in JS - it will be 10 times worse to fix) :).
     
    Last edited: Dec 15, 2019
  19. OZAV

    OZAV

    Joined:
    Aug 9, 2013
    Posts:
    293
    We don't use Y axis for velocity for runs (translations forward-back), unless you want the object to take off (up vertically), for translation forward-back is the best to use Z axis, which is horizontal one in Unity. So ... assumedly Y is vertical axis - anything with Y axis used (with any +- value of more than zero in it), will give you the jumps or falls down, so simply avoid any numbers higher than zero for any axis in your game object that is pointed up, if you want translations forward-back, eg, walk, run, drive, etc, you work with Z and X axes numbers for that (assumedly they are horizontal ones), hope it helps :).
     
    Last edited: Dec 15, 2019
    danil2272002 likes this.
  20. danil2272002

    danil2272002

    Joined:
    Dec 11, 2019
    Posts:
    18
    I have a 2D game, and when I want my character to go I need to do velocity.y to jump velocity.x, I just don’t understand why it is so? I watched the review, the boy also had it, and it's kind of normal
     
  21. danil2272002

    danil2272002

    Joined:
    Dec 11, 2019
    Posts:
    18
    What do you mean by the word things?
    objects or what?
     
  22. danil2272002

    danil2272002

    Joined:
    Dec 11, 2019
    Posts:
    18
    The fact is that when I put rb.velocity.y I have a player with x coordinate, everyone has it, but I can’t understand why, and when I use rb.velocity.y and rb.velocity.x then everything is fine y == y coordinate x == x coordinate
     
  23. danil2272002

    danil2272002

    Joined:
    Dec 11, 2019
    Posts:
    18
    and don’t forget that I have 2D