Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by zuuGee · Feb 08, 2018 at 10:34 PM · c#scripting problemphysicsgravity

How to fix initial gravity problem?

this works for the most part, like once i get up to 80 on the y axis my gravity shuts off but there is like an persistent gravity on the rigid body that stays until there is a collision with the ground. and only after that first collision with the ground plane will the gravity be turned off the way I would like it to.

 public Rigidbody asteroid;
 public Rigidbody player;

 void Update () {
     
     if (transform.position.y > 80)
     {
         GetComponent<Rigidbody>().useGravity = false;

     }
  }

the asteroids stay up in the air like they are supposed to.

any help with this would be much appreciated.

thanks in advanced.

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
1
Best Answer

Answer by Nazirzadeh · Feb 09, 2018 at 12:00 AM

Hi, First of all, FixedUpdate should be used instead of Update when dealing with Rigidbody.

Also you can simply freez it's position`transform.rigidbody.constraints = RigidbodyConstraints.FreezePositionY;`

Keep in mind,if you set the useGravity to false the rigidbody will behave as in outer space. If an objects enters to a 0 gravity space, it continuous movement based on his last speed. You need to take care of its speed too.

Comment
Add comment · Show 4 · 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 zuuGee · Feb 09, 2018 at 12:07 AM 0
Share

the FixedUpdate informations is much appreciated, but I cant really use the constraint because I would like to be able to move on the y axis as well as all other axis. And as far as it behaving like it was in outer space that is kinda the idea.

avatar image zuuGee · Feb 09, 2018 at 12:13 AM 0
Share

that is exactly what I am looking for how would I go about zeroing out the speed of that object?

avatar image Nazirzadeh zuuGee · Feb 09, 2018 at 12:19 AM 1
Share

Look this zero veclocity

avatar image zuuGee · Feb 09, 2018 at 12:52 AM 0
Share

I am actually stupid your first comment actually works fine with what I am trying to do, for some reason I thought it would affect my movement script. but it does not so thank you very much for the response.

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

77 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 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 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 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 can I change friction of a Physic material in script? 1 Answer

How to make Rigidbody.AddForce less delayed in Unity3D? 0 Answers

Object jumps right after the attached HingeJoint2D is Enabled 0 Answers

Question on 2d planet gravity 1 Answer

walk on walls (third person) 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