Posts: 5
Threads: 1
Joined: Apr 2022
Reputation:
0
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
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
20-04-2022, 06:37 PM
(This post was last modified: 20-04-2022, 06:39 PM by josemendez.)
(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
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?
Posts: 5
Threads: 1
Joined: Apr 2022
Reputation:
0
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.
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
(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...
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,
Posts: 5
Threads: 1
Joined: Apr 2022
Reputation:
0
(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:
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
21-04-2022, 12:09 PM
(This post was last modified: 21-04-2022, 12:09 PM by josemendez.)
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
Posts: 5
Threads: 1
Joined: Apr 2022
Reputation:
0
(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 , 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() ?
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
21-04-2022, 02:41 PM
(This post was last modified: 21-04-2022, 03:15 PM by josemendez.)
(21-04-2022, 02:21 PM)Cysar Wrote: I do not understand that , 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,
Posts: 5
Threads: 1
Joined: Apr 2022
Reputation:
0
I see
So the AddForce function should be the best way.
An sample code about calculate the velocity for the AddForce function would be great ^^
|