22-02-2019, 06:44 PM
(This post was last modified: 22-02-2019, 06:48 PM by josemendez.)
(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 vector, Vector3 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/