22-02-2019, 11:35 PM
(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.