Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Dogg · Aug 09, 2014 at 05:49 AM · gravitydisable

(C#)How To Disable Gravity From Script?

Yes I know there are lot's of questions about this, but when I try to get them to work they give me errors when I use the most common way: Rigidbody.useGravity or Rigidbody2D.useGravity. It says that rigidbody or rigidbody2D doesn't contain a definition of useGravity. So how can I disable my gravity then? Is there a way to change the location of the gravity from rigidbody2D to my character script? Like a bool or something.

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

4 Replies

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

Answer by zharik86 · Aug 09, 2014 at 06:39 AM

Use reference on rigidbody:

  //For rigidbody
  this.rigidbody.useGravity = false;

  //For rigidbody2D
  this.rigidbody2D.gravityScale = 0.0f;

I hope than it will help you

Comment
Add comment · Show 3 · 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 Dogg · Aug 09, 2014 at 09:08 PM 0
Share

Yes it helped me a lot thank you.

avatar image vnunity · Oct 04, 2014 at 02:53 AM 0
Share

I change gravityscale=0 in rigidbody2d component then It work for disable my character fall down But when I use velocity=new vector(5,0) for my character move horizontal it run straight away with no stop position.

Is there any solution for disable gravity can use addforce function and velocity for moving horizontal ?

avatar image thealexguy1 · Jan 27, 2016 at 02:19 AM 0
Share

Thanks that worked for me too :)

avatar image
3

Answer by Rugbug_Redfern · Sep 29, 2017 at 01:01 AM

 GameObject.GetComponent<Rigidbody>().useGravity = false;
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 d2clon · Nov 26, 2020 at 06:30 PM 0
Share

gameObject.GetComponent<Rigidbody>().useGravity = false;

First letter small case

avatar image
1

Answer by Melann · Sep 28, 2017 at 06:13 PM

There is a new answer, and it is not documented in the Scripting API:

Turning off gravity from script.

This is what the Scripting documentation tells you to do: gameObject.rigidbody.useGravity = false;

This is the error message you get when you do that: Assets/Scripts/ReceiveTaps.cs(59,14): error CS0619: UnityEngine.GameObject.rigidbody' is obsolete: Property rigidbody has been deprecated. Use GetComponent() instead. (UnityUpgradable)'

And this is how it works: gameObject.GetComponent ().useGravity = false;

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

Answer by chriswagie · Feb 08 at 11:16 PM

bruh you don't know me but i've been stuck trying to make an object drop on another object's destruction for a month now (I'm new, in the unity tutorials) and with your answer i was finally able to do it. Thank you soooooo much.

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

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

27 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

Related Questions

Multiple Cars not working 1 Answer

Disable a script on collision 2 Answers

hide object start script 4 Answers

Faux Gravity Prolem? #2 2 Answers

Delete object when two collision or more 1 Answer


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