Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Constrain particles on axis
#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


Messages In This Thread
Constrain particles on axis - by Richard - 22-02-2019, 09:38 AM
RE: Constrain particles on axis - by josemendez - 22-02-2019, 10:37 AM
RE: Constrain particles on axis - by Richard - 22-02-2019, 11:08 AM
RE: Constrain particles on axis - by josemendez - 22-02-2019, 11:27 AM
RE: Constrain particles on axis - by Richard - 22-02-2019, 12:22 PM
RE: Constrain particles on axis - by josemendez - 22-02-2019, 12:57 PM
RE: Constrain particles on axis - by Richard - 22-02-2019, 01:22 PM
RE: Constrain particles on axis - by josemendez - 22-02-2019, 02:02 PM
RE: Constrain particles on axis - by Richard - 22-02-2019, 02:49 PM
RE: Constrain particles on axis - by josemendez - 22-02-2019, 03:01 PM
RE: Constrain particles on axis - by Richard - 22-02-2019, 03:31 PM
RE: Constrain particles on axis - by josemendez - 22-02-2019, 03:46 PM
RE: Constrain particles on axis - by Richard - 22-02-2019, 03:55 PM
RE: Constrain particles on axis - by josemendez - 22-02-2019, 06:44 PM
RE: Constrain particles on axis - by Richard - 22-02-2019, 11:35 PM