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
1
Question by MarmAmic · Oct 11, 2010 at 03:46 PM · rigidbodygravity

Gravity.cs help?

Hi,

I can see gravity questions have very little answers but I will try anyway.

I am trying to use the gravity.cs script from the unify wiki.

Not working.

I have put an object next to my game object which should be the center of the gravity well but nothing happens. The object is not being pulled towards the center of the gravity well.

I am sure it is within the range.

Any help would be welcome? I am a new programmer and new to unity so please use baby steps with me :)

Maybe I am doing something wrong with the Rigid bodies... Please help.

Thanx,

Amichai

Comment
Add comment · Show 2
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 _Petroz · Oct 11, 2010 at 08:15 PM 0
Share

Not everyone will be familiar with the 'gravity.cs' script. Add a link so we don't have to go search it to help you.

avatar image MarmAmic · Oct 12, 2010 at 03:06 PM 0
Share

you are right Petroz.

Link is http://www.unifycommunity.com/wiki/index.php?title=Gravity

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by duck · Oct 11, 2010 at 08:58 PM

Have you added a Rigidbody component to the objects(s) which should be affected by the gravitational pull?

The gravity script only affects objects which have a rigidbody component attached. Also make sure that "Is Kinematic" is not checked, on the rigidbody component.

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 MarmAmic · Oct 12, 2010 at 03:06 PM 0
Share

I have of course done those things.

avatar image
1

Answer by dmpaskiet · Oct 12, 2010 at 05:01 AM

1st thing: I'm pretty sure both your "planet" object and the object you want to be affected by its gravity have to have rigidbodies attached to them.

2nd thing: Make sure "gravity" is turned off on both of the rigidbodies, or it will cause them to naturally fall downward instead of towards the planet you want them to.

3rd thing: The normal setting on the script in the wiki is very very light. Try increasing the mass of your planet as this will increase the effect of its gravity quite a bit.

I'm using the script (albeit a slightly modified version), and as long as you do at least the first two things and you are within range, it should work no problem.

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 MarmAmic · Oct 12, 2010 at 03:09 PM 0
Share

Tried all 3 options and nothing worked.

avatar image
0

Answer by MarmAmic · Oct 12, 2010 at 03:09 PM

I have started checking what the offset, offset.sqrMagnitude and offset / offset.sqrMagnitude were giving me.

They kept giving me 0, 0, 0.

What I did is remove the offset.sqrMagnitude calculation so now it looks like this:

Vector3 force = offset * rigidbody.mass;

It works but I think it works kinda weird.

Do any of you have any other ideas?

Comment
Add comment · Show 6 · 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 dmpaskiet · Oct 12, 2010 at 04:34 PM 0
Share

Are you using this in a 2D or 3D setting? If it's 3D the only other thing I could think is the object may look in range on the x and y axis, but be in actuality out of range on the z axis. $$anonymous$$ind of a longshot, but I don't see why else the script shouldn't work as is.

avatar image MarmAmic · Oct 13, 2010 at 02:05 PM 0
Share

I am using this in a 2D setting or actually in a 2D like setting. Orthographic and static camera but the objects are 3D.

avatar image dmpaskiet · Oct 13, 2010 at 06:50 PM 0
Share

And you're positive all of your objects are on 0 on your z-axis?

avatar image MarmAmic · Oct 14, 2010 at 09:41 AM 0
Share

actually they are on 100 in the Z axis...

avatar image dmpaskiet · Oct 14, 2010 at 09:23 PM 0
Share

And your player object is on 100 as well then?

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

No one has followed this question yet.

Related Questions

hit.normal cube 0 Answers

moving at certain circumstances 1 Answer

Turn Gravity on when collision occurs 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

A* Rigidbody. Aron Granberg 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