Obi Official Forum
Help Constrain particles on axis - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Cloth (https://obi.virtualmethodstudio.com/forum/forum-2.html)
+--- Thread: Help Constrain particles on axis (/thread-924.html)

Pages: 1 2


Constrain particles on axis - Richard - 22-02-2019

Can I constrain particles on x, y or z axis?


RE: Constrain particles on axis - josemendez - 22-02-2019

(22-02-2019, 09:38 AM)Richard Wrote: Can I constrain particles on x, y or z axis?

Yes, simply project their position/velocity to the desired axis, using Vector3.Project.
https://docs.unity3d.com/ScriptReference/Vector3.Project.html


RE: Constrain particles on axis - Richard - 22-02-2019

(22-02-2019, 10:37 AM)josemendez Wrote: Yes, simply project their position/velocity to the desired axis, using Vector3.Project.
https://docs.unity3d.com/ScriptReference/Vector3.Project.html

Sorry, but I could not realize well. The reference states how to change the direction, not to constrain. Or is there another way?


RE: Constrain particles on axis - josemendez - 22-02-2019

(22-02-2019, 11:08 AM)Richard Wrote: Sorry, but I could not realize well. The reference states how to change the direction, not to constrain. Or is there another way?

Constraining an object so that it moves in a certain direction is equivalent to projecting its velocity vector to that direction, which you can do using that function.

In the link I provided, there's an example that constrains a rail-mounted gun so that it only moves along the rail direction. You can do the same for particles, so that they only move in a given axis.


RE: Constrain particles on axis - Richard - 22-02-2019

(22-02-2019, 11:27 AM)josemendez Wrote: Constraining an object so that it moves in a certain direction is equivalent to projecting its velocity vector to that direction, which you can do using that function.

In the link I provided, there's an example that constrains a rail-mounted gun so that it only moves along the rail direction. You can do the same for particles, so that they only move in a given axis.

Why the document combine transform and vector like (Transform target, Vector3 railDirection)?

I cannot add rigidbody to particles so that I add constrain on axis?


RE: Constrain particles on axis - josemendez - 22-02-2019

(22-02-2019, 12:22 PM)Richard Wrote: Why the document combine transform and vector like (Transform target, Vector3 railDirection)?

I cannot add rigidbody to particles so that I add constrain on axis?

Hi,

That's simply a function with two input parameters. You should read more on how C# and programming in general works, as these are very basic issues.

You don't need to add a rigidbody component to particles, they already have a velocity.  In fact you could not add a component to them even if you wanted, as they are not GameObjects. You just need to use Vector3.Project on their velocity, that's it.


RE: Constrain particles on axis - Richard - 22-02-2019

(22-02-2019, 12:57 PM)josemendez Wrote: Hi,

That's simply a function with two input parameters. You should read more on how C# and programming in general works, as these are very basic issues.

You don't need to add a rigidbody component to particles, they already have a velocity.  In fact you could not add a component to them even if you wanted, as they are not GameObjects. You just need to use Vector3.Project on their velocity, that's it.
Hello.
That is a hard problem for me. Although the template is public static Vector3 Project(Vector3 vectorVector3 onNormal);, transform is applied in the case.

In case of public static Vector3 Project(Vector3 vector, Vector3 onNormal);, Vector3 vector means actual movement of particle (with nothing processing) and Vector3 onNormal means direction I want them to move ( if I constrain on y and z axis, vector3 (0, 1, 1)), and then Vector3 Project is how I would like them to move?


RE: Constrain particles on axis - josemendez - 22-02-2019

(22-02-2019, 01:22 PM)Richard Wrote: Hello.
That is a hard problem for me.

That's why you should read more on the subject (Unity, C# and basic vector algebra) before attempting to use advanced physics simulations. The problem itself is trivial, you just don't have enough knowledge to tackle it yet. Asking others to solve it for you is not going to help you in the long run, at all.

(22-02-2019, 01:22 PM)Richard Wrote: In case of public static Vector3 Project(Vector3 vector, Vector3 onNormal);, Vector3 vector means actual movement of particle (with nothing processing) and Vector3 onNormal means direction I want them to move.

Yes, the "vector" variable should be the vector you want to project, in this case the particle's velocity. "onNormal" should be the vector you want to project it onto, in your case the axis.

(22-02-2019, 01:22 PM)Richard Wrote: if I constrain on y and z axis, vector3 (0, 1, 1)), and then Vector3 Project is how I would like them to move?

I think you're mixing up vectors and planes. Constraining something to move on both Y and Z (or X and Z, Z and Y) is done by projecting to a plane, not a vector. By projecting velocity to a vector you essentially get rid of all movement except along that vector.

So by projecting to (0,1,1), you're making particles move only along the (0,1,1) vector, which is a diagonal line crossing the YZ plane.

To allow a particle to move only in the YZ plane, you'd have to use Vector3.ProjectOnPlane. You'd then pass (1,0,0) as the plane normal.
https://docs.unity3d.com/ScriptReference/Vector3.ProjectOnPlane.html


RE: Constrain particles on axis - Richard - 22-02-2019

(22-02-2019, 02:02 PM)josemendez Wrote: That's why you should read more on the subject (Unity, C# and basic vector algebra) before attempting to use advanced physics simulations. The problem itself is trivial, you just don't have enough knowledge to tackle it yet. Asking others to solve it for you is not going to help you in the long run, at all.


Yes, the "vector" variable should be the vector you want to project, in this case the particle's velocity. "onNormal" should be the vector you want to project it onto, in your case the axis.


I think you're mixing up vectors and planes. Constraining something to move on both Y and Z (or X and Z, Z and Y) is done by projecting to a plane, not a vector. By projecting velocity to a vector you essentially get rid of all movement except along that vector.

So by projecting to (0,1,1), you're making particles move only along the (0,1,1) vector, which is a diagonal line crossing the YZ plane.

To allow a particle to move only in the YZ plane, you'd have to use Vector3.ProjectOnPlane. You'd then pass (1,0,0) as the plane normal.
https://docs.unity3d.com/ScriptReference/Vector3.ProjectOnPlane.html
The trivial c# problem you think is method? And constrain on YZ plane means particle move on the plane, is it OK?


RE: Constrain particles on axis - josemendez - 22-02-2019

(22-02-2019, 02:49 PM)Richard Wrote: The trivial c# problem you think is method? And constrain on YZ plane means particle move on the plane, is it OK?

Using Vector3.Project or Vector.ProjectOnPlane to constraint a velocity vector, I think is trivial.

Yes, by constraining to YZ plane I mean the particles can only move on that plane.