Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Force not moving objects

Discussion in 'Physics' started by Sahkulu, Nov 27, 2014.

  1. Sahkulu

    Sahkulu

    Joined:
    Jul 24, 2014
    Posts:
    4
    I have a problem with force and rigidbody. I want my player character to use a glider object and fly with it when i press the key. There are two objects and each object has one script attached to it.
    "maincharacter" object has UserControl script in it,
    while the "glider" object has GliderBehave script inside.
    When i run the:
    if (Input.GetKeyDown (KeyCode.Q)){ rigidbody.AddForce (-9300.0f, 0.0f, 0.0f); }
    inside GliderBehave script without doing anything else, it works like it should be, it pushes the glider forward when i press the button. But i want maincharacter to run this method before that happens:
    public void startGliding(GameObject gli){//this method is inside usercontrol script
    gliding = true;
    glider = gli;
    rigidbody.useGravity = false;
    transform.position = glider.transform.position+gliderEdge;
    transform.rotation = glider.transform.rotation;
    }
    which will change the maincharacter position and rotation, and also will make it stay unaffected from the gravity.
    But the usage of startGliding method somehow stops the force from making glider move. I am puzzled and don't have an idea about why is this happening. Any help which will offer a solution to this unknown problem is appreciated, thank you :)

    Note: I know that rigidbody.addforce is currently only pushing the glider forward, not the maincharacter with it. But that is not my problem here, i just want to make glider move for now.
     
  2. cl9-2

    cl9-2

    Joined:
    May 31, 2013
    Posts:
    417
    One possibility is using a fixed joint if both the player and the glider object have rigid body components.
     
  3. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    Your mass is probably too high. In your game, no mass should be more than 100 times greater than the mass of any other object. Good numbers to use for mass if you're trying to keep things stable are between 0.01 and 1.00. I finally got a car that I could drive when I dropped all of the numbers down to this level. Some tutorials were recommending mass as high as 30,000+ so they could use forces that were in the thousands... I just decided to read the documentation and found that little tidbit about the mass.

    If it isn't mass, it's your drag. If it's neither, it could be a kinematic object. Really, the possiblities are great.
     
    cl9-2 likes this.
  4. cl9-2

    cl9-2

    Joined:
    May 31, 2013
    Posts:
    417
    I missed this part. You'll probably want to provide more information about the rigid body and transform settings of the object you want to glide and the transform setting for the glider. I tried a similar script without any problems.
     
    RJ-MacReady likes this.
  5. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    It's usually some little detail, some box checked but in my experience you never hear from the OP again once you solve the problem they're gone