Obi Official Forum
about softbody Collision - 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: about softbody Collision (/thread-2801.html)



about softbody Collision - zero16832 - 11-03-2021

how to get the collision point?

thx for your help


RE: about softbody Collision - josemendez - 11-03-2021

(11-03-2021, 12:33 PM)zero16832 Wrote: how to get the collision point?

thx for your help

It's part of the contact struct. You can get both the point on the simplex surface (as barycentric coordinates) or on the collider surface (expressed in solver space):

See:
http://obi.virtualmethodstudio.com/tutorials/scriptingcollisions.html


RE: about softbody Collision - zero16832 - 11-03-2021

(11-03-2021, 12:40 PM)josemendez Wrote: It's part of the contact struct. You can get both the point on the simplex surface (as barycentric coordinates) or on the collider surface (expressed in solver space):

See:
http://obi.virtualmethodstudio.com/tutorials/scriptingcollisions.html
I just need the first collision point witch api can i use?


RE: about softbody Collision - josemendez - 11-03-2021

(11-03-2021, 12:48 PM)zero16832 Wrote: I just need the first collision point witch api can i use?

What do you mean by the "first" collision point? there can be multiple collision points at once in a single frame...


RE: about softbody Collision - zero16832 - 11-03-2021

(11-03-2021, 12:54 PM)josemendez Wrote: What do you mean by the "first" collision point? there can be multiple collision points at once in a single frame...
I make a ground and a control softbody in scene . when the sofybody collision with the ground,this first collision


RE: about softbody Collision - josemendez - 11-03-2021

(11-03-2021, 12:58 PM)zero16832 Wrote: I make a ground and a control softbody in scene . when the sofybody collision with the ground,this first collision

It’s not entirely clear to me, sorry. First collision since when? in the game? since last time the ground and the softbody where in contact? First particle that contacts the ground? First contact reported in the list of contacts for a single frame?

An object might collide with another during a single frame, or multiple frames.
You can get all contacts for the current frame using the collision callbacks API, see the link above. You can simply subscribe to the OnCollision event and grab the first contact in the list, if that’s what you are after.


RE: about softbody Collision - drmgmt32 - 20-02-2022

I'm hoping to get extra detail on this question.

Would it be possible to give an example or an explanation of how to convert from both barycentric coordinates and solver space to global space?

Thank you for any help you can give!


RE: about softbody Collision - josemendez - 21-02-2022

(20-02-2022, 05:07 AM)drmgmt32 Wrote: I'm hoping to get extra detail on this question.

Would it be possible to give an example or an explanation of how to convert from both barycentric coordinates and solver space to global space?

Thank you for any help you can give!

Unity has built-in functions to convert data between spaces, as it's very a basic and common operation. See the Transform class:
https://docs.unity3d.com/ScriptReference/Transform.html

The methods you're interested in are:
TransformPoint/Direction/Vector: from local space to global space.
InverseTransformPoint/Direction/Vector: from global space to local space.

So to transform a particle position from the solver's local space to global space:
Code:
var worldPos = solver.transform.TransformPoint(solver.positions[index]);

You should definitely get familiar with vector spaces and converting data between them, as it's paramount when making games of any kind. There's a lot of online resources regarding vector spaces. For instance:
https://m-ansley.medium.com/local-space-and-world-space-in-unity-970e0bfb7694
http://blog.lidia-martinez.com/transformation-matrices-spaces-linear-algebra-unity

Barycentric coordinates are also very common. Given the barycentric coordinates of a point in a triangle, you get the point by simply multiplying each coordinate by the corresponding vertex, and adding it all together:

Code:
// "t" is the triangle, "bary" the barycentric coords.
var point = t.vertex1 * bary.x + t.vertex2 * bary.y + t.vertex3 * bary.z;

If the triangle was expressed in some transform's local space -like a triangle simplex in Obi- and you want the result in global (aka "world") space, you'd just use the above functions.

let me know if you need further help. kind regards,