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

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.

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.

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?