Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by NaesDraw · May 03, 2014 at 08:36 PM · rigidbodyvector3velocityaddrelativeforce

Rigidbodies with fixed joint connection rotate instead of forward/back

Here's the situation. I have a scene with no gravity, and a ship that I move with add relative force/torque. It's all Newtonian physics, so equal and opposite reactions are the order of the day. It's not perfect, but with my very small time constraints it's good enough.

Problem: I have a rigidbody cargo that you pick up with a fixed joint. So envision a ship, with a container underslung. The connect/disconnect works like a charm. Now, we push forward thrust, and go into front flips. Back gives the same result, only back. My other movements, pitch, roll, yaw, transverse all mostly work. They have slight drift in odd angles but I assume it's all related.

I've played with masses and the other rigidbody settings but don't seem to be resolving the issue.

I doubt it's something currently in my code, but if anyone wants a detail I will provide it.

Here's the thrust code in any case, and yes I know what the directions are, I had some weird kludgery but this does otherwise work like a charm.

 if(Input.GetButton("Prograde")){ //Accel
          rigidbody.AddRelativeForce (Vector3.left * thrustSpeed  / 4);
          fuel -= thrustSpeed / 20;
 }//end pro
 
 if(Input.GetButton("Retrograde")){ //Decel
      rigidbody.AddRelativeForce (Vector3.right * thrustSpeed / 4);
      fuel -= thrustSpeed / 20;
 }//end retro
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NaesDraw · May 05, 2014 at 03:51 PM 0
Share

Removed .normalize, and I assume you mean something like,

 In Update()
  
 if(docked){ 
        direction = (cargo.transform.TransformPoint(cargo.rigidbody.centerOf$$anonymous$$ass)+transform.transform.TransformPoint(rigidbody.centerOf$$anonymous$$ass))/2;
     }

I did this, and tried. I touched the prograde key at the lowest thrust setting and I spun into the roof so quickly I barely had time to see before instantly fatal impact. Whoops. Seeing as that seems to have made it worse, is there something else I'm missing? Don't think there's any other relevant code.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Jeff-Kesselman · May 03, 2014 at 09:30 PM

Attaching the cargo moves your center of gravity. So now, when you put a force on the ship, its off center and it makes it flip. This is exactly what would happen in space without correctional forces :)

Either determine the new center of gravity and point your acceleration force at it, OR set your cargo mass (including the arm picking it up) to 0.

Comment
Add comment · Show 18 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NaesDraw · May 04, 2014 at 01:33 AM 0
Share

$$anonymous$$mmm. I suspected that might have been the problem, i.e. what you said about the center of gravity, but as I'd said before I messed with masses to no avail. However, after learning that mass doesn't allow 0, I set it to something equivalently tiny and was pleased to see it work. The only trouble is, a mass that low plays havoc with collisions, which is why I wanted fixed joint in the first place. I played around a bit but nothing with enough mass to do solid collisions didn't adversely effect pro/retrograde movement.

So, not quite sure how I'd go about adjusting the force to the new center, tips?

avatar image Jeff-Kesselman · May 04, 2014 at 06:30 PM 0
Share

Sure. If you have 3 connected bodies, of equal mass, then the center of mass of the entire fixture is (centerofmass1+centerofmass2+centerofmass3)/3.

If they aren't of equal mass then you need to weight the calculation with the mass: ((cenertofmass1*mass1)+(centerofmass2*mass2)+(centerofmass3*mass3)/(mass1+mass2+mass3)

In either case this will give you a Vector3 that is the proper center of mass.

Use this as the position with "AddForceAtPosition"

avatar image NaesDraw · May 04, 2014 at 07:24 PM 0
Share

$$anonymous$$mmm. Seems like it should work, but I suspect there's an orientation issue co$$anonymous$$g up. It seems like the container's direction has something to do with it, because now I'm getting various different rotations ins$$anonymous$$d. I can't be sure which direction the container will be when the player picks it up, so not sure what do with this. Telling the container to rotate to ship.transform.rotation on dock had the unfortunate side effect of catapulting me clear out of the hangar.

I have a plan B if I can't get this to work, but it seems much more realistic.

avatar image Jeff-Kesselman · May 05, 2014 at 02:57 AM 0
Share

How are you getting the centers of mass, from https://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-centerOf$$anonymous$$ass.html ?

That returns the center of mass relative to the local origin. So you would need to use gameObject.transfrom.TransformPoint(gameObject.rigidbody.centerOf$$anonymous$$ass) to get the CO$$anonymous$$ in world space, which is what you need.

avatar image NaesDraw · May 05, 2014 at 03:10 AM 0
Share

$$anonymous$$mmm, well, that isn't how I was doing it, but I get the same result with that in ins$$anonymous$$d.

  direction = (cargo.transform.TransformPoint(cargo.rigidbody.centerOf$$anonymous$$ass)+transform.transform.TransformPoint(rigidbody.centerOf$$anonymous$$ass))/2;

With my movement code as:

  if(Input.GetButton("Prograde")){ //Accel
             if(!docked){
                  rigidbody.AddRelativeForce (Vector3.left * thrustSpeed  / 4);
              }
              else{ 
                  rigidbody.AddForceAtPosition (direction.normalized,Vector3.left * thrustSpeed  / 4);
              }
              //audio.PlayOneShot(clipEngine, 0.5);
              fuel -= thrustSpeed / 20;
         }//end pro
     
         if(Input.GetButton("Retrograde")){ //Decel
             if(!docked){
                  rigidbody.AddRelativeForce (Vector3.right * thrustSpeed / 4);
              }
              else{
                  rigidbody.AddForceAtPosition (direction.normalized,Vector3.right * thrustSpeed  / 4);
              }
              fuel -= thrustSpeed / 20;
              //audio.PlayOneShot(clipEngine, 0.5);
         }//end retro

So, what am I doing wrong?

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to set velocity to a previouse value 1 Answer

Slow down a character while they are midair while keeping their original velocity 0 Answers

Changing 1 parameter of rigidbody.velocity (Vector3) 2 Answers

What is wrong with this rigidbody? 2 Answers

How would I counteract the force of the velocity and set it to zero after the input has stopped? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges