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

Wheel Joint 2d motor?

Discussion in '2D' started by engelcj, Oct 8, 2014.

  1. engelcj

    engelcj

    Joined:
    May 20, 2014
    Posts:
    122
    Hi guys,
    Connect my wheels to physical wheel joint 2d. What I do is like changing the motor speed from a script c #.

    Can you help me?
    Tips are welcome!:D

    Thank you :)
     
    TFumers likes this.
  2. CalaveraX

    CalaveraX

    Joined:
    Jul 11, 2013
    Posts:
    143
    Check out my video about how to do it
    Cheers
     
  3. CalaveraX

    CalaveraX

    Joined:
    Jul 11, 2013
    Posts:
    143
     
    engelcj likes this.
  4. falconer

    falconer

    Joined:
    Feb 6, 2013
    Posts:
    21
  5. SpitFire001

    SpitFire001

    Joined:
    Nov 12, 2015
    Posts:
    2
    none of these tutorials help i have been looking for answer for haow to change the motorspeed for wheel joint the first tow videos are just adding wheels and the third one is too complicated to the question that i am looking for and contain a code without complecation like i want just to know how to put a speed value like -500f in a code line that will be like wheeljoint2d.motorspeed(-500f) or = -500f could anyone help me with this problem please
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
  7. Morhem

    Morhem

    Joined:
    Jan 24, 2015
    Posts:
    6
    People, are you kidding me? Sorry for resurrecting, but I have the same problem, and noone actually answered here.
    *Typed and deleted angry message about how none of what suggested above are relevant, or works.*
    I figured it out. You cannot change speed or force directly in Joint, or its motor. You need to create NEW JointMotor2D, adjust speed and torque, and then assign this motor to joint. Like this:
    MyJoint.useMotor = true;
    var MyNewMotor= new JointMotor2D();
    MyNewMotor.motorSpeed = 1000;
    MyNewMotor.maxMotorTorque = 10000;
    MyJoint.motor = motor;
     
  8. PaperPrototype

    PaperPrototype

    Joined:
    Jan 3, 2018
    Posts:
    6
    Wow, thank you, finally someone who can answer this.
     
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    I'm hoping that you know that this is C# and when you set a field on a struct, you're ALWAYS setting a copy of it because that's what a struct in C# is i.e. a value type. The motor settings are a struct so you need to set the struct.

    This means when you retrieve the motor settings on a joint (or any other property that returns any struct in Unity or any C# app) you get a COPY as this is how structs work in C#. Changing the field of that won't change the original value.

    It sounds like you're confused over how structs work in C# but glad you've sorted it out.

    Note that the last post here was in 2016. ;)
     
    Last edited: Apr 10, 2020
    Murmer likes this.
  10. loover

    loover

    Joined:
    Oct 18, 2014
    Posts:
    6
    So how to make a fast moving car? 2D side view. Tutorials show only a slowly moving car (like in a parking). But how to speed it up? Like Formula 1. Like
    (but mainly for straight line). I tried different options, but as a result, for a stable moving in a straight line, the speed remains approximately the same. What I tried:
    Increasing the speed of rotation of the wheels (at a certain speed, they try to tear themselves away from the car body, car twitches and jumps); сhange in wheel/body mass; change friction for road/wheels; damping change; angular drag changes; change for gravity.
    All changes were both increase and decrease.
     
  11. jeremysmitherman

    jeremysmitherman

    Joined:
    May 28, 2017
    Posts:
    6
    Here's an idea: improve your documentation to make it more obvious that you're dealing with a struct here because your only indication short of calling IsValueType or relying on your IDE to tell you is a tiny breadcrumb of text under the title of the page that's almost the same color as the background. It's very much not the same workflow as the vast majority of the API. It's a very confusing thing to run into and answers like this are helpful, but so many questions like this should indicate to you that your documentation is more insufficient than the programmer's C# knowledge.
     
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    You mean like it explicitly saying "struct" in the documentation?

    This is shown for every type in the Unity engine like here: https://gyazo.com/c7d04bd0023f9036991b2831a7729ff6

    You're complaining about it not being in the documentation (when it is in there) which can only suggest you're not looking at the documentation. Documentation is only useful if you look at it.