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 meathelix · Aug 31, 2013 at 12:10 AM · physicsrigidbodyfpsspaceship

How do I keep rigid bodies from sliding when applying fake gravity based on moving parent?

Ok, so the setup here is a little complex. I'm trying to simulate people and things being inside of a ship moving through space.

To achieve this effect, I've made this temp ship out of cube walls and floors and grouped all of that under a "Ship" object in the hierarchy. I've also placed the player there as well.

I wrote a custom character controller for the player, applying velocity to a RB capsule and then applying fake gravity in the FixedUpdate. I'm doing the same thing to RB boxes I've placed around the ship.

The problem is that the objects and player slide across the floor, indicating that something is off in my transform hierarchy assumptions.

The fake gravity is a force applied along the down (negative up) vector of the ship's transform. I assumed that would just work, but I guess I was wrong.

Here are the relevant code bits.

In the ship script:

void FixedUpdate() {

     transform.Rotate(new Vector3(0,0,Time.deltaTime * 10));
 
     Vector3 tempVec;
     tempVec = transform.up * -98f;
     foreach(Rigidbody rb in rigidBodies)
     {
         //Gravity!!
         if(rb.gameObject.tag != "Player")
         {                
             rb.AddForce(tempVec, ForceMode.VelocityChange);
         }
     }
 }

And in the player script:

 void FixedUpdate()
     {        
                         
         rigidbody.velocity = lateralMoveVector*(moveSpeed);
         
         //Gravity!!
         rigidbody.AddForce(transform.parent.up * -98 * rigidbody.mass, ForceMode.Force);
     }

I've tried adjusting the friction on the child objects, as well as using rigid body physics motion on the parent ship instead of a forced rotate.

The friction had no effect, and using rigid body motion on the parent caused the player and other RB children to completely float away from the floor of the ship. This is a big problem, as I intended on steering the parent with RB physics once this was sorted out.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by meat5000 · Aug 31, 2013 at 12:11 AM

Add Physic materials (some have more friction than others) and increase drag on your RigidBodies.

Little discrepancy in your code, I see -98f in one and -98 in the other gravity. 98 is very high, and one is f and not the other. Probably wont make much difference though.

Maybe declare a variable for it at the start to be consistent.

Also, Forcemode acceleration might be a better model for that kind of Physics? I don't know its up to you.

Comment
Add comment · Show 1 · 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 meathelix · Aug 31, 2013 at 03:14 AM 0
Share

I've actually tried friction and drag values in the rigidbody and Physic materials with little to no success.

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

18 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

Related Questions

How to stop an rigidbody enemy from jumping when chasing the player? 1 Answer

Why won't my rigidbody fps controller move? 1 Answer

Does setting the rotation of an object override the physics engine? 1 Answer

Low framerate on physics initialization. 0 Answers

Stop rigidbody A from applying physics to rigidbody B while still allowing collisions between the 2 objects 0 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