# Converting Local to World Forces in gravity simulation.

 0 I have a semi-realistic solution to orbital gravity but it has several problems: It uses a system that only allows body-body gravity. It works in local space. It makes my planets turn unrealistically. It only works for large objects(planets, moons, stars) I'd like to find a way to convert the local forces to world forces and store them in variables, then apply them in world space.I think that I should describe this more in depth, so here we go.At the moment my system has two spheres of different sizes childed to there own empty objects. The empty object is rotated (problem 3) to face the other's sphere, so the planets turn as the empty object turns and we all know this doesn't happen. Then, a second script uses a function to find the distance between them and does this equation g = (GxM1xM2)/(DxD). This gives output in Newtons, then I divide it by its imaginary mass. Imaginary mass is a mass to large to simulate with the ridgedbody. This gives a force of Newtons equal to Meters per Second Squared if the mass of the ridgedbody is 1kg. Then, I apply this as a constant force in the local Z (problem 2) direction of the empty object (Ridgedbody's mass is set to 1kg). Now, I have gravity! So as the "planet" is childed to the empty object, it will not work for an object (spaceship) that has other forces applied to it (problem 4). Also, it can only face one object at a time. Therefore the force can only be applied in one local z direction. Making it impossible to create a multi-body gravity simulation where a moon pulls on a planet while it gets pulled on by its planet's star (problem 1).I can put up the scripts if it helps but not if you dont need them. If you need more explantion on a aspect of the system I can supply that to.Thanks for the help. more ▼ asked Jul 11 '12 at 06:46 AM XSSA -6 ● 6 ● 7 ● 8 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 why can't you add force to rigidbodies in different directions?http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForce.htmlyou can calculate force for each pair of obects and apply force every FixedUpdate() in relative directions - unique for each pair. also it's better to ignore far-placed pairs to make calculations lighter, close object's gravity is much more powerful then far-placed, so you can ignore it in usual game. more ▼ answered Jul 14 '12 at 12:56 PM ScroodgeM 7.6k ● 2 ● 6 this is what i want to accomplish but i'm not sure how to calculate the forces for the individual axis Jul 16 '12 at 03:04 AM XSSA you have two objects in position pos1 and pos2 (Vector3). just take (pos2-pos1) and you'll got direction from pos1 to pos2, so you must apply force to obj1 in this direction, and to obj2 in opposite directionhttp://answers.unity3d.com/questions/284173/distinguish-between-two-colliding-objects.htmljust like this but inverse directions Jul 16 '12 at 04:16 AM ScroodgeM thanks so much for your help at first i was really confused but when i figured out you needed to normalize the vector3 it worked! but now a small and probably obvious question how to you apply a world constant force because it seams i can only apply a relative force and that wont work for a spinning planet or ship? Never mind i found the answer in the spelling you have to use a lower case when spelling .force facehoof /)-(\ Jul 16 '12 at 09:36 PM XSSA add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x460
x69
x12
x9

asked: Jul 11 '12 at 06:46 AM

Seen: 412 times

Last Updated: Jul 16 '12 at 09:51 PM