Obi Official Forum

Full Version: How to simulate Planet gravity
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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;
solver.PushSolverParameters();

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/manua...icles.html
my code is
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;

public class Test : MonoBehaviour
{
    ObiSolver solver;
    void Start()
    {
        solver = transform.GetComponent<ObiSolver>();
       
    }
    void Update()
    {
        Debug.Log(solver.transform.position);
       
    }
}
this script on the Obi Solver
but result always (0.0,0.0,0.0)
but rope is moving;
Did i make a mistake?
(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.

Please take a look at the manual's architectural overview:
http://obi.virtualmethodstudio.com/manua...cture.html
http://obi.virtualmethodstudio.com/manua...olver.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
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;"
(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 vectorHuh

(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).
i want to know the box center position
(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
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?
Thank you very much
I go to try Gran sonrisa