- Home /
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
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.
you are right Petroz.
Link is http://www.unifycommunity.com/wiki/index.php?title=Gravity
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.
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.
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?
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.
I am using this in a 2D setting or actually in a 2D like setting. Orthographic and static camera but the objects are 3D.
And you're positive all of your objects are on 0 on your z-axis?
Your answer
Follow this Question
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