Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Constrain particles on axis
#1
Can I constrain particles on x, y or z axis?
Reply
#2
(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...oject.html
Reply
#3
(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...oject.html

Sorry, but I could not realize well. The reference states how to change the direction, not to constrain. Or is there another way?
Reply
#4
(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.
Reply
#5
(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?
Reply
#6
(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.
Reply
#7
(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?
Reply
#8
(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...Plane.html
Reply
#9
(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...Plane.html
The trivial c# problem you think is method? And constrain on YZ plane means particle move on the plane, is it OK?
Reply
#10
(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.
Reply