Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Constrain particles on axis
#11
(22-02-2019, 03:01 PM)josemendez Wrote: 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.
Does transform include meaning of velocity vector?
Reply
#12
(22-02-2019, 03:31 PM)Richard Wrote: Does transform include meaning of velocity vector?

Sorry, but I don't fully understand the question.
If you're asking whether a transform has a "velocity" property, no it doesn't. A transform is composed of position, rotation and scale. No velocity or other physical attributes whatsoever.

Particles in Obi are not transforms either. They're just an index, that can be used to access their position, velocity, mass, etc. See:
http://obi.virtualmethodstudio.com/tutor...icles.html
Reply
#13
(22-02-2019, 03:46 PM)josemendez Wrote: Sorry, but I don't fully understand the question.
If you're asking whether a transform has a "velocity" property, no it doesn't. A transform is composed of position, rotation and scale. No velocity or other physical attributes whatsoever.

Particles in Obi are not transforms either. They're just an index, that can be used to access their position, velocity, mass, etc. See:
http://obi.virtualmethodstudio.com/tutor...icles.html

I had to explain more. In the link you showed me has a code void Slide(Transform target, Vector3 railDirection) although the template is public static Vector3 Project(Vector3 vectorVector3 onNormal);, and you said "Using Vector3.Project or Vector.ProjectOnPlane to constraint a velocity vector". So I asked that question.

I try to move some particle by transform, too. Obi's velocity is moved by vector?
Reply
#14
(22-02-2019, 03:55 PM)Richard Wrote: I had to explain more. In the link you showed me has a code void Slide(Transform target, Vector3 railDirection) although the template is public static Vector3 Project(Vector3 vectorVector3 onNormal);, and you said "Using Vector3.Project or Vector.ProjectOnPlane to constraint a velocity vector". So I asked that question.

I try to move some particle by transform, too. Obi's velocity is moved by vector?

You cannot move a particle by changing its transform, because it does not have one. Particles are moved by changing their velocity, which is a vector. Like this:
Code:
// solver index of the first particle in the actor.
int particleSolverIndex = actor.particleIndices[0];

// use it to set the particle's current velocity.
solver.velocities[particleSolverIndex] = <your vector here>;

The code in the link is just an example. They have defined a custom function Slide(Transform target, Vector3 railDirection), which calculates a heading vector by subtracting the gameObject's  position (transform.position) from the the target transform (passed by parameter), hence:
Code:
Vector3 heading = target.position - transform.position;

Then they use Vector3.Project() to project this heading vector onto the rail direction:
Code:
Vector3 force = Vector3.Project(heading, railDirection);

And feed that as a force to the rigidbody component:
Code:
GetComponent<Rigidbody>().AddForce(force);


This is a extremely basic script. Please learn how programming works before attempting to do more complex stuff. I will not answer any more questions unless they're directly related to Obi. For C#/Unity related questions, please use this forum instead:

https://forum.unity.com/forums/scripting.12/
Reply
#15
(22-02-2019, 06:44 PM)josemendez Wrote: You cannot move a particle by changing its transform, because it does not have one. Particles are moved by changing their velocity, which is a vector. Like this:
Code:
// solver index of the first particle in the actor.
int particleSolverIndex = actor.particleIndices[0];

// use it to set the particle's current velocity.
solver.velocities[particleSolverIndex] = <your vector here>;

The code in the link is just an example. They have defined a custom function Slide(Transform target, Vector3 railDirection), which calculates a heading vector by subtracting the gameObject's  position (transform.position) from the the target transform (passed by parameter), hence:
Code:
Vector3 heading = target.position - transform.position;

Then they use Vector3.Project() to project this heading vector onto the rail direction:
Code:
Vector3 force = Vector3.Project(heading, railDirection);

And feed that as a force to the rigidbody component:
Code:
GetComponent<Rigidbody>().AddForce(force);


This is a extremely basic script. Please learn how programming works before attempting to do more complex stuff. I will not answer any more questions unless they're directly related to Obi. For C#/Unity related questions, please use this forum instead:

https://forum.unity.com/forums/scripting.12/

Sorry, I should do so.
Reply