Obi Official Forum
Is it able to move softbody with script? - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Softbody (https://obi.virtualmethodstudio.com/forum/forum-12.html)
+--- Thread: Is it able to move softbody with script? (/thread-1366.html)

Pages: 1 2


Is it able to move softbody with script? - harapeco - 16-09-2019

Hello.

I'd like to move softbody object with script.
for example, attach above code to softbody object.


Code:
using UnityEngine;
using System.Collections;

public class Gravity : MonoBehaviour {
   public GameObject planet;      
   public float accelerationScale;
    
    void FixedUpdate () {
        
        var direction = planet.transform.position - transform.position;
        direction.Normalize();

        GetComponent<Rigidbody>().AddForce(accelerationScale * direction, ForceMode.Acceleration);
    }
}


Is it able to  do this?

or if not, how can i do like this.


RE: Is it able to move softbody with script? - tegleg - 23-09-2019

like this


Code:
        GetComponent<ObiActor>().AddForce(accelerationScale * direction, ForceMode.Acceleration);


have a look at AddRandomVelocity.cs used in the ball pool demo


RE: Is it able to move softbody with script? - manurocker95 - 12-11-2019

(23-09-2019, 12:44 AM)tegleg Wrote: like this


Code:
        GetComponent<ObiActor>().AddForce(accelerationScale * direction, ForceMode.Acceleration);
have a look at AddRandomVelocity.cs used in the ball pool demo

and how do I set an obi actor by transform position?


RE: Is it able to move softbody with script? - josemendez - 12-11-2019

(12-11-2019, 04:11 PM)manurocker95 Wrote: and how do I set an obi actor by transform position?

Hi,

Mathematically speaking it is impossible to define the orientation/position/scale of any deformable object using a single transform. Where's the "center" of a t-shirt? how much is it rotated/scaled when worn? and when folded in a drawer? or crumpled in the laundry basket?

So you have to be much more specific about what you mean by "set by transform position".

- You could fix some particles in your actor, and then set the position of those (ObiHandles).
- You could perform the simulation in local space, then move the reference frame of the simulation around. See: http://obi.virtualmethodstudio.com/tutorials/localspace.html


RE: Is it able to move softbody with script? - manurocker95 - 13-11-2019

(12-11-2019, 04:42 PM)josemendez Wrote: Hi,

Mathematically speaking it is impossible to define the orientation/position/scale of any deformable object using a single transform. Where's the "center" of a t-shirt? how much is it rotated/scaled when worn? and when folded in a drawer? or crumpled in the laundry basket?

So you have to be much more specific about what you mean by "set by transform position".

- You could fix some particles in your actor, and then set the position of those (ObiHandles).
- You could perform the simulation in local space, then move the reference frame of the simulation around. See: http://obi.virtualmethodstudio.com/tutorials/localspace.html

I already made another thread, but now I have a grasper that must be able to grab an object and pull it while it deforms. Now, for doing things simple, it follows the grasper transform while moving it, so I need the entire object to follow that transform. Actually, the example grabber is what I need but without that bouncing effect.


RE: Is it able to move softbody with script? - josemendez - 13-11-2019

(13-11-2019, 01:25 PM)manurocker95 Wrote: I already made another thread, but now I have a grasper that must be able to grab an object and pull it while it deforms. Now, for doing things simple, it follows the grasper transform while moving it, so I need the entire object to follow that transform. Actually, the example grabber is what I need but without that bouncing effect.

Why not slightly modifying the included grabber then? Instead of adding a force to each particle (solver.externalForces, which is what the grabber does) set their position directly (set solver.positions instead). If you want the grabbed particles to have no dynamics while grabbed, also set their inverse mass and their velocity to zero.


RE: Is it able to move softbody with script? - manurocker95 - 14-11-2019

(13-11-2019, 02:42 PM)josemendez Wrote: Why not slightly modifying the included grabber then? Instead of adding a force to each particle (solver.externalForces, which is what the grabber does) set their position directly (set solver.positions instead). If you want the grabbed particles to have no dynamics while grabbed, also set their inverse mass and their velocity to zero.
The thing is that:

1) I need to know what particles are being touched by the grasper and any of the current callbacks allow to know that
2) Even if I set the position of the dragged particles, I need the rest of the particles to follow the position but applying dynamic physics, so could you make an example to know how would it be done?


RE: Is it able to move softbody with script? - josemendez - 14-11-2019

(14-11-2019, 09:54 AM)manurocker95 Wrote: The thing is that:

1) I need to know what particles are being touched by the grasper and any of the current callbacks allow to know that
2) Even if I set the position of the dragged particles, I need the rest of the particles to follow the position but applying dynamic physics, so could you make an example to know how would it be done?

1) You can use collision callbacks to get the particles touching the grasper:
http://obi.virtualmethodstudio.com/tutorials/scriptingcollisions.html

2) When you set the position of some particles, all other particles follow them automatically because they are interlinked via shape matching constraints. There's nothing you need to do for this to happen. Simply move the particles you need, the rest will follow.


RE: Is it able to move softbody with script? - manurocker95 - 14-11-2019

(14-11-2019, 10:18 AM)josemendez Wrote: 1) You can use collision callbacks to get the particles touching the grasper:
http://obi.virtualmethodstudio.com/tutorials/scriptingcollisions.html

2) When you set the position of some particles, all other particles follow them automatically because they are interlinked via shape matching constraints. There's nothing you need to do for this to happen. Simply move the particles you need, the rest will follow.


About 1) gonna try that, but more examples should be added to the package to cover these kind of things.

2) Not really: https://gofile.io/?c=mbKTnQ

the script just set the positions as:     

solver.positions[pickArgs.particleIndex] = (targetPosition);


RE: Is it able to move softbody with script? - josemendez - 14-11-2019

(14-11-2019, 10:24 AM)manurocker95 Wrote: About 1) gonna try that, but more examples should be added to the package to cover these kind of things.

2) Not really: https://gofile.io/?c=mbKTnQ

the script just set the positions as:     

solver.positions[pickArgs.particleIndex] = (targetPosition);

Hi Manu,

The video you sent causes VLC, Quicktime and Media Player to crash, so I'm unable to see it.

When setting positions directly you also need to set the inverse mass and the velocity of these particles to zero, as I pointed out before. Setting the inverse mass to zero deactivates dynamics for that particle (as you will be setting its position directly, and you don't want the simulation to overwrite it), and removing all its velocity will make sure it doesn't drift away from the position you set.

Once you "release" the particle, simply set its inverse mass to whatever it was. The simulation will take over and begin setting both its position and velocity.

From the manual:
http://obi.virtualmethodstudio.com/tutorials/scriptingparticles.html
Quote:Inverse mass for each particle. An inverse mass of 0 means the particle's mass is infinite, so its position will be unaffected by dynamics (allowing you to override it manually).