Help How to simulate Planet gravity - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: General (https://obi.virtualmethodstudio.com/forum/forum-5.html) +--- Thread: Help How to simulate Planet gravity (/thread-3153.html) |
How to simulate Planet gravity - wushuaiqi - 27-10-2021 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 Or there are other solutions Thank you for your help RE: How to simulate Planet gravity - josemendez - 27-10-2021 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: Code: var pos = solver.transform.position; To set its gravity, you do: Quote:solver.parameters.gravity = yourGravity; See the API docs for details. 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/manual/6.2/scriptingparticles.html RE: How to simulate Planet gravity - wushuaiqi - 27-10-2021 my code is Code: using System.Collections; but result always (0.0,0.0,0.0) but rope is moving; Did i make a mistake? RE: How to simulate Planet gravity - josemendez - 27-10-2021 (27-10-2021, 10:52 AM)wushuaiqi Wrote: this script on the Obi Solver 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. Please take a look at the manual's architectural overview: http://obi.virtualmethodstudio.com/manual/6.2/bigpicture.html http://obi.virtualmethodstudio.com/manual/6.2/obisolver.html 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 RE: How to simulate Planet gravity - wushuaiqi - 27-10-2021 Thank you for your answer But I still don't know how to get solver center position Do solver position and set gravity position overlap? Can I trouble you for an example? And what is solver in"var pos = solver.transform.position;" RE: How to simulate Planet gravity - josemendez - 27-10-2021 (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). RE: How to simulate Planet gravity - wushuaiqi - 27-10-2021 i want to know the box center position RE: How to simulate Planet gravity - josemendez - 27-10-2021 (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/manual/6.2/scriptingparticles.html RE: How to simulate Planet gravity - josemendez - 27-10-2021 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? RE: How to simulate Planet gravity - wushuaiqi - 27-10-2021 Thank you very much I go to try |