Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Move Softbody to position
#1
Hello,
how can I move the position of the softbody to the red ball and let them follow when I move the red ball?
I have checked this website (Obi Physics for Unity - Scripting Particles) but its not helping me Triste 
[Image: 77af2d89d0921af3b33f2415eb5e7232.gif]
Reply
#2
(20-04-2022, 06:28 PM)Cysar Wrote: Hello,
how can I move the position of the softbody to the red ball and let them follow when I move the red ball?
I have checked this website (Obi Physics for Unity - Scripting Particles) but its not helping me Triste 
[Image: 77af2d89d0921af3b33f2415eb5e7232.gif]

Hi,

The red ball seems to be just a transform, no physics affecting it. It’s not clear to me what you goal is: should the softbody simply spawn at the red ball’s position and then follow physics (fall due to gravity, collide with floor etc) or be forced to be at the red ball position every frame? (that would effectively prevent any softbody simulation)

If you’ve tried scripting particles to do this, what have you tried so far? Could you share the code you’re currently using?
Reply
#3
Yes the red ball is just a transform.
I have created a blue ball (also just a transform) and now imagine that the blue ball is the soft body.
I tested the 3 scripts from the documentation, everything works, but I don't know what to do with it...
Right now I removed all the script from the softbody object.

[Image: 55deaf66603ba9c40b6e84b8d2669903.gif]
Reply
#4
(20-04-2022, 07:10 PM)Cysar Wrote: I tested the 3 scripts from the documentation, everything works, but I don't know what to do with it...

[Image: 55deaf66603ba9c40b6e84b8d2669903.gif]

There's several ways you could go about this. One is to specify particle positions, but that would overwrite simulation results. Assuming you want the softbody to still react to collisions and accelerations while following the red ball, the simplest approach is to use the softbody.AddForce() function. This works just like Unity's rigidbody.AddForce().

Calculate a vector from the softbody to the red sphere, scale it by the intensity of the force you want to apply, and then call AddForce(yourScaledForceVector). That will make the softbody follow the sphere.

Let me know if I can be of further help,
Reply
#5
(21-04-2022, 10:40 AM)josemendez Wrote: There's several ways you could go about this. One is to specify particle positions, but that would overwrite simulation results. Assuming you want the softbody to still react to collisions and accelerations while following the red ball, the simplest approach is to use the softbody.AddForce() function. This works just like Unity's rigidbody.AddForce().

Calculate a vector from the softbody to the red sphere, scale it by the intensity of the force you want to apply, and then call AddForce(yourScaledForceVector). That will make the softbody follow the sphere.

Let me know if I can be of further help,
The softbody is swinging faster and faster, is there an calculation to not swing around the red ball?

This is my current script:

Transform tr;
    public Transform trTarget;
    public ObiActor actor;

    void Start()
    {
        tr = transform;
    }

    public float speed = 6;
    void Update()
    {
        actor.AddForce((trTarget.position - tr.position) * speed, ForceMode.Acceleration);
    }



Result:

[Image: ea3f53643998097032ec8924373ddb36.gif]
Reply
#6
What you wrote is a regular spring: Force = -kx (where K is the "speed" constant, and x the distance between the red ball and the softbody).

You could add a dampening factor to control and reduce oscillation. See:
https://phys.libretexts.org/Bookshelves/...cillations
Reply
#7
(21-04-2022, 12:09 PM)josemendez Wrote: What you wrote is a regular spring: Force = -kx (where K is the "speed" constant, and x the distance between the red ball and the softbody).

You could add a dampening factor to control and reduce oscillation. See:
https://phys.libretexts.org/Bookshelves/...cillations
I do not understand that Indeciso , so I just googled "unity velocity Damped Oscillations" and I found this (A simple follow script using damped harmonic motion : Unity3D (reddit.com)
The problem is this is working when I use rigidbody.velocity = velocity but its not wokring when I try to use rigidbody.AddForce(velocity) is it possible to use something like ObiActor.velocity instead of ObiActor.AddForce() ?
Reply
#8
(21-04-2022, 02:21 PM)Cysar Wrote: I do not understand that Indeciso , so I just googled "unity velocity Damped Oscillations" and I found this (A simple follow script using damped harmonic motion : Unity3D (reddit.com)
The problem is this is working when I use rigidbody.velocity = velocity but its not wokring when I try to use rigidbody.AddForce(velocity) is it possible to use something like ObiActor.velocity instead of ObiActor.AddForce() ?

This won't work because softbodies don't have a single velocity value, unlike rigidbodies.

The linear velocity of a rigidbody is that of its center of mass, since all points in it move in unison: it cannot deform, it's "rigid". A softbody however doesn't have a single velocity value. Each individual particle can move in a different direction at a different speed. You need to modify the velocity of each individual particle.

The manual explains how to set particle velocities (or any other per-particle property): http://obi.virtualmethodstudio.com/manua...icles.html

Let me know if you need some sample code.

kind regards,
Reply
#9
I see  Sonrisa

So the AddForce function should be the best way.
An sample code about calculate the velocity for the AddForce function would be great ^^
Reply