space time fabric in unity 3 (indie)

I’m currenlty working on a practical assignment for physics, and w’re making a little simulation of the universe. I wanted to make einstein’s space-time fabric/grid in unity3d (indie), which curves around massive objects like planets (see picture).

Is this accomplishable ?? with cloth physics or line renderer???
The scene is not big, because i scaled down every big distance.
I tried to make a spacetime fabric by myself with cloth physics but I don’t know how to curve it, in script.
(see attachment)

pls help me out!! :smile:
.

an interesting concept. You could use a terrain, set all the heights to 100%, then in the program, find each object that you want to adjust and adjust the height according to the gravitational pull of a planet.

All you would have to do is figure out which x,y coordinate the planet is above and multiply the displacement to spread it out for the distance in a Vector2 format.

I don’t know if you could update this every frame or not though, that would be hard.

In the case of SetHeights, you could develop strips instead of setting each vertex at a time.

If you wanted a mesh specfically or round mesh, you would have to generate the mesh, the uv’s and texture it. You could do this just about every frame if the mesh size wasn’t huge. (20k vertices or so)

Lastly, you could simply generate the whole thing in a 3d app and fake it all… lol.

If you are looking for the exact math to create the field. I am sure Unity can do it, but it would involve alot of calculation from object to space displacement.

hmmm I think terrain isn’t a good idea, because it will slow down the framerate and I want the simulation to go smooth.

what do mean by this??? I don’t get it.

Can’t you do this with cloth physics and then calculate the pressure/depth of the cloth in a certain area?? how do you ajust the depth of a cloth???

if I were you I would do it by using the mesh class. you can use a plane with a grid texture, than push the vertices based on the distance from a planet.

Of course.

+1.

(It would take a little work, but what I’d probably do is generate a mesh procedurally for which the vertices corresponded to the nodes in the mesh, and then displace the vertices using an appropriate formula or algorithm. Or, you could create the mesh in a modeling program and just manipulate the vertices.)

Your trip starts here:

build a mesh, add a MeshFilter to an empty game object, make it’s mesh the mesh you created. Keep the mesh handy. Use your calculations to redo the vertices as you go.

var mesh : Mesh;
var planet : Transform;
var gravWell=100;// distance modifier

var verts=mesh.vertices;
for(i=0; i<verts.length; i++){
var worldPos=Vector2(transform.position.x + vert[i].x,transform.position.z + vert[i].z);
// this is a linear affect. replace it with whatever you want.
var gravityAffect=planet.mass - Vector2.Distance(Vector2(planet.position.x, planet.position.y), worldPos) * gravWell;
vert[i].y=vert[i].y - gravityAffect;
}
gameObject.GetComponent(MeshFilter).mesh.vertices=verts;// update the mesh vertices

I’m going to geek out for a bit here and point out that the “fabric” visualization is actually sort of incorrect. That visualization represents the density of spacetime as a drop in position perpendicular to the grid/plane being shown.

In reality, gravity is a deformation of the spatial coordinates system, wherein the closer a given point is to a given mass, the closer it is shifted towards that mass.

So, using text to demonstrate a linear set of coordinates, when the points are unaffected by gravity, they look like this:
0----------1----------2----------3----------4----------5----------6----------7----------8
then if you place a body of mass at the location of the 4th coordinate, you’d get something that looks more like this:
0-----------------1-----------2-------3—|4|—5-------6-----------7-----------------8

Now lets say you have these two lines next to each other, like so:
Line A
0----------1----------2----------3----------4----------5----------6----------7----------8
0-----------------1-----------2-------3—|4|—5-------6-----------7-----------------8
Line B

If these two lines exist simultaneously, next to each other on a coordinate plane, then its easy to see how as you move from coordinate 4 on Line A to 4 on Line B, the position in space stays the same, but as you move from 3A to 3B, there is a dramatic change in relative position, even though the horizontal coordinate is the same.

What is more, is that as an object shifts its position due to coordinate changes, its directional momentum remains relative to the non-deformed coordinates system. This is why an asteroid traveling past the sun will not pull in close and then be propelled back towards its original path - it will “bend” around the sun instead.

SO…
that said, I think a better representation would be to construct a 3D matrix of points, then shift those points closer to a given point of mass, decreasing the amount of shift exponentially as the distance from the mass increases. Then show an object traveling along this coordinate system, with the direction of its momentum being influenced by these shifts.

:stuck_out_tongue:

The actual problem that I have with that whole theory is that everyone expresses it in a 2d sense. The whole envelope shown above is truly expressed in that sense. All the theory suggests is that planets have gravity and that gravity affects particles as they pass near or through the object. Objects closer are drawn to the gravametric source while objects farther away are not.

It is expressed as a 2d and shown as that to give the sense that things fall downwards therefore if you display something with a deep spot, the general masses will get the concept that things are drawn towards it’s center. Gravity by it’s self is akin more to magnetism and is perpetuated on our planet more due to the high iron concentration of the core rather than just mass. So a planet with less Iron would theoretically have less of a gravitational pull, more with more. I suspect that larger planets like Jupiter and Saturn gaseous as we perceive them to be are actually high Iron planets, thus have massive gravitational pulls. This could easily support the large gas atmosphere’s that they posses and pull large bodies into orbit with them.

I could be wrong… it’s just a theory and one that I could never prove. The wonderful thing about theories is that they aren’t fact.

Back to the reasoning for the code… The section that I gave you measures the distance from the vertex location in world space to the center of the object in question.

//after much thought, change this code:
var worldPos=Vector2(transform.position.x + vert[i].x,transform.position.z + vert[i].z);


//to this:
var worldPos=Vector2(transform.position.x + vert[i].x,transform.position.z + vert[i].z) * Vector2(transform.localScale.x, transform.localScale.z);

did you test your code at all? it throws back all types of errors:
namely vert is not defined, you defined verts, and you can’t multiply Vector2 * Vector2, it gives this back:

Huge issue, if one were to simulate negative gravity, as in antimatter (I think that’s what it is), then you would not be able to bend the mesh in the other direction