hi I want to know how to simulate Planet gravity
my idea is
change gravity direction point to planet position in update() The direction calculation formula is
Vector3 dir=(solver.position(box center)-planet.position).normalized so i want to know how to get solver center position or gravity set position
27-10-2021, 10:37 AM (This post was last modified: 27-10-2021, 10:39 AM by josemendez.)
Hi there,
Depending on how large your planet is, using a single gravity vector for the entire solver might not be a good solution. Assuming the planet is really, really large compared to the solver, you can use the same gravity for all particles in the solver.
The solver is just a regular GameObject, so you get its position the usual way:
However if your planet is small enough, using the same gravity for all particles won't do. Each individual particle in the solver must have its own gravity vector, since you can't assume all gravity vectors are close to parallel to each other.
In this case, the best solution is to set the global solver's gravity to zero, and apply your own gravity to each particle as an external acceleration. You do this by writing into the solver's velocities array. See: http://obi.virtualmethodstudio.com/manua...icles.html
27-10-2021, 10:59 AM (This post was last modified: 27-10-2021, 11:15 AM by josemendez.)
(27-10-2021, 10:52 AM)wushuaiqi Wrote: this script on the Obi Solver
but result always (0.0,0.0,0.0)
but rope is moving;
Did i make a mistake?
I think you're confusing solvers and actors.
This is a very basic, very important concept: actors (such as ropes) are objects made of particles. Solvers contain actors. Actors can move freely inside the space defined by its solver, and there can be multiple actors inside a solver.
You can think of the solver as the "world" or "container" of sorts, in which the rope lives. Even though the world is not moving, the rope can move freely within it.
You can also think of the solver as a pond, and actors (ropes) as fish inside the pond. The pond does not move, but the fish do.
This ties right into the concept of vector spaces, used in virtually every field of making games: physics, graphics, AI, etc: https://en.wikipedia.org/wiki/Vector_space
27-10-2021, 11:18 AM (This post was last modified: 27-10-2021, 11:20 AM by josemendez.)
(27-10-2021, 11:15 AM)wushuaiqi Wrote: But I still don't know how to get solver center position
solver.transform.position. That is the solver's center position.
(27-10-2021, 11:15 AM)wushuaiqi Wrote: Do solver position and set gravity position overlap?
I don't know what you mean by "gravity position", gravity is not a position but a vector.
(27-10-2021, 11:15 AM)wushuaiqi Wrote: And what is solver in"var pos = solver.transform.position;"
"solver" is a variable of type ObiSolver, that is, a reference to a solver.
These are very basic programming/physics concepts. If you're new to Unity or game physics you will find Obi to be very hard and confusing to use, since it's aimed at advanced users. I'd recommend reading up on C# programming, transform hierarchies and basic physics (forces, accelerations, impulses, mass, etc).
27-10-2021, 11:22 AM (This post was last modified: 27-10-2021, 11:23 AM by josemendez.)
(27-10-2021, 11:18 AM)wushuaiqi Wrote: i want to know the box center position
That's neither the solver's position, nor the rope's position. That's the rope's center of mass.
To calculate the center of mass of a deformable object, simply do a mass-weighted average of all particle's positions. You have sample code for this in the scripting section of the manual: http://obi.virtualmethodstudio.com/manua...icles.html
27-10-2021, 11:25 AM (This post was last modified: 27-10-2021, 11:26 AM by josemendez.)
In your image, I guess the grey sphere is your "planet".
You won't be able to apply a single gravity value to the entire solver. The planet is small enough for different parts of the rope to be affected by different gravity vectors.
Calculating the rope's center of mass and somehow applying a single gravity value there (which is what I think you want) will not work. You must apply a different gravity vector to each individual particle. Does this make sense?