Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  How do I set a particle position at runtime ?
#5
(29-03-2020, 07:12 PM)josemendez Wrote: Particle positions (and velocities, radii, ... all particle properties) are expressed in solver space. So if you pass a solver space position to Gizmos.Draw() (which by default expects data to be expressed in world space), the drawn position and the actual particle position won't match at all. You must express the position in world space before drawing it, or set Gizmos.matrix accordingly. See: https://docs.unity3d.com/ScriptReference...atrix.html

Setting particle positions in FixedUpdate() works just fine for me. Can you share your code?

Yes of course Sonrisa .
However changing the matrix for the Gizmos displays them at the wrong position. For some unknown reasons, those gizmos are already at the right place.

Here is for the code. I instantiate the ropes in this object : 
Code:
 void Awake() {

   this.mesh = GetComponent<MeshFilter>().mesh;
   this.vertices = mesh.vertices;
   this.normals = mesh.normals;


   for (int i = 0; i < this.vertices.Length; i++) {
     this.ropeObj = Instantiate(this.prefab);
     this.rope = ropeObj.GetComponent<ObiRope>();
     this.rope.transform.parent = this.prefab.transform.parent;

     // that's where I add in my other script
     this.ropeObj.AddComponent<Strand>();
     this.currentVertice++;
     if (i == 0)
       break; // For now, let's keep this to one rope.
   }

Now this is the script component attached to the generated ropes : 
Code:
void Awake() {

   this.scalp = GameObject.FindWithTag("scalp").GetComponent<Scalp>();
   this.start = this.scalp.getNextVertice();
   this.normal = this.scalp.getNextNormal();

   this.makeStrand();
}

private /*IEnumerator*/ void makeStrand () {

   this.rope = gameObject.GetComponent<ObiRope>();
   ObiRopeCursor cursor = this.rope.GetComponent<ObiRopeCursor>();
   this.solver = this.rope.GetComponent<ObiSolver>();


/*  //## No longer making a new blueprint ##

[size=small][font=Monaco, Consolas, Courier, monospace]    this.localHit = this.rope.transform.InverseTransformPoint(this.start);[/font][/size]
   Vector3 end = this.rope.transform.InverseTransformPoint(this.normal);
   ObiRopeBlueprint blueprint = ScriptableObject.CreateInstance<ObiRopeBlueprint>();
   blueprint.resolution = 0.5f;
   blueprint.path.Clear();
   blueprint.path.AddControlPoint(
       localHit, -localHit.normalized, localHit.normalized, -end.normalized,
       0.1f, 0.1f, 1, 1, Color.white, "start");
   blueprint.path.AddControlPoint(
       localHit + (end.normalized * 2) , end.normalized, end.normalized, Vector3.up,
       0.1f, 0.1f, 1, 1, Color.white, "end");
   blueprint.path.FlushEvents();
   this.rope.ropeBlueprint = blueprint;
*/

    this.rope.solver.positions[this.rope.solverIndices[solverIndex]] = this.start;

   // I already have the particle attachment on the prefab
   //this.rope.GetComponent<ObiParticleAttachment>().particleGroup = this.rope.ropeBlueprint.groups[0];

   Strand.index++;

   /*yield return blueprint.Generate()*/
}

 void FixedUpdate() {

   this.last = this.rope.solverIndices.Length - 1;
   this.first = this.rope.solverIndices[0];
   this.rope.solver.positions[this.rope.solverIndices[solverIndex]] = this.start;
 }

I feel like there is something really really obvious I am missing. Is there anything that looks wrong to you, Jose ?
Thank you so much for your help so far and for those amazing assets.
Reply


Messages In This Thread
RE: How do I set a particle position at runtime ? - by slugGoddess - 31-03-2020, 09:49 AM