Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is it able to move softbody with script?
#1
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.
Reply
#2
like this


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


have a look at AddRandomVelocity.cs used in the ball pool demo
Reply
#3
(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?
Reply
#4
(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/tutor...space.html
Reply
#5
(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/tutor...space.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.
Reply
#6
(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.
Reply
#7
(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?
Reply
#8
(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/tutor...sions.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.
Reply
#9
(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/tutor...sions.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);
Reply
#10
(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/tutor...icles.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).
Reply