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
0
Question by shepsaus000 · Dec 07, 2015 at 06:28 PM · scripting problemrigidbodyinspectorrigidbody physics

How do I apply gravity, but only in the y-axis?

In Unity, the gravity feature located on a Rigidbody does indeed apply an acceleration in the y direction on an object, but for some reason it also applies air resistance. It's like it slows the object in the x and z directions. I was wondering if there was a way either through scripting or even just through some fines in the inspector that can help me get a rigid body to only be affected on the y axis.

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 Bonfire-Boy · Dec 09, 2015 at 09:41 AM 0
Share

As others have said, gravity operates on the y axis only. Implementing your own gravity system doesn't seem like a smart way to resolve this. I think whatever's going on here isn't what you think it is. A video or even just a diagram showing the trajectory the object is taking might help.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by TommyEaves2002 · Dec 07, 2015 at 06:45 PM

In terms of scripting you could put this line of code in your update function:

 rigidbody.addForce(new Vector3(0, gravity, 0));

Remember to make gravity a negative value ;) Also rigidbody needs to be a variable with the rigidbody you want to apply the force to as a value. If you don't know how to do this put this in your start function:

 rigidbody = this.gameobject.GetComponent<Rigidbody3D>();


Comment
Add comment · Show 7 · 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 Eno-Khaon · Dec 07, 2015 at 07:07 PM 0
Share

To add a little more detail, Unity's gravity vector only adds to an object's velocity in the direction it pushes. If your velocity is (5, 0, 0) and gravity pulls your object down for 10 seconds, that 5 on the X-axis will not be changed due to gravity alone.

Rigidbody drag or collision friction, on the other hand, are what will slow your object down. Drag is calculated as:

 rigidbody.velocity *= $$anonymous$$athf.Clamp01(1.0f - (rigidbody.drag * Time.fixedDeltaTime));

This also happens to mean that if rigidbody.drag / Time.fixedDeltaTime >= 1 your object will stop all motion every frame.

avatar image shepsaus000 Eno-Khaon · Dec 08, 2015 at 06:48 PM 0
Share

I already have my drag set to 0 in the inspector, and yet, my object continues to fail to maintain its horizontal velocity. Any ideas?

avatar image Eno-Khaon shepsaus000 · Dec 08, 2015 at 08:32 PM 0
Share

Well, to throw a few more questions out there, then, do you have any scripts modifying velocity in any way? Is there ever any point when friction might become a factor due to contact with another object? Is there any odd chance that there's a mix-up between velocity and rotational velocity?

To be honest, I'm not entirely sure where the problem would lie in this case. I've put together trajectory prediction scripts with no faults in their accuracy (including factoring in drag), so I can only guess that the problem might be found in something overlooked.

Show more comments
avatar image TommyEaves2002 · Dec 07, 2015 at 09:50 PM 0
Share

In that case I am sorry but I cannot help.

avatar image
0

Answer by Fanttum · Dec 07, 2015 at 09:02 PM

You can change global gravity settings Edit>ProjectSettings>Physics also knows as the Physics Manager.

You might also be thinking of Drag that is slowing down your Rigidbody. Make sure it is set to zero so it won't slow down. Also maybe see Friction?

Comment
Add comment · Show 2 · 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 shepsaus000 · Dec 08, 2015 at 06:48 PM 0
Share

I already have my drag set to 0 in the inspector, and yet, my object continues to fail to maintain its horizontal velocity. Any ideas?

avatar image Fanttum shepsaus000 · Dec 08, 2015 at 09:28 PM 0
Share

And it is in the air? Can I see an example?

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

35 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

Related Questions

There is no GameObject attached to this GameObject 2 Answers

Script reference not showing in inspector 0 Answers

Rigidbody movement with turns for a one wheeled motor cycle. 0 Answers

Best Strategy to interact with rigidbody 2 Answers

Why is my vertical movement faster than my horizontal? 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