Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Closed loop rope, move particles to stretch it
#1
Good morning,

i am creating a simulation where everytime the game gets loaded there is an example shape around some nails an elastic has to reach. 
the elastic is represented by a closed loop obirope. 

in the start method i call a function that sets the elastic global position based on the shape. Now i woul dlike to actually move 2 or 3 particles to create the shape and hook the nails i need to
private void Start()

{
    repetition = GameManager.Instance.GetCurrentRepetition();
    Debug.Log("repetition is : " + repetition);
    SetNailsAndElastic(repetition);

}

private void SetNailsAndElastic(int repetitionNumber)
{
    GameObject[] allNails = GameObject.FindGameObjectsWithTag("Nail");
    foreach (GameObject nail in allNails)
    {
        nail.GetComponent<Renderer>().material = defaultMaterial;
    }
    switch (repetitionNumber)
    {
        case 1:
            HighlightNails(new string[] { "nail_1_r1", "nail_c_r1" });
            Debug.Log("in rep1");
            elastic.transform.position = new Vector3(-2.17000008f, 0.810000002f, -10.4899998f);
            elastic.TeleportParticle(82, new Vector3(1, 3, 5));

            //elastic.blueprint.positions[82] =  new Vector3(1, 3, 5);

}

this is a small snippet of my code, and this is what i try to do to move that specific particle for example. 
The particle doesn't move though, even if the elastic takes the right position i wrote there

do you have any advice??
Reply
#2
Hi there!

TeleportParticle() won't do anything if the particle referenced by the index does not exist, or if the actor has not been loaded into the solver yet. So by calling it on Start() you may be calling it before the solver has had a chance to initialize itself and loaded the actor.

Either check actor.isLoaded to see if the actor has been added to the solver, or call it on actor.OnBlueprintUnloaded() instead.

kind regards,
Reply
#3
(Yesterday, 12:20 PM)josemendez Wrote: Hi there!

TeleportParticle() won't do anything if the particle referenced by the index does not exist, or if the actor has not been loaded into the solver yet. So by calling it on Start() you may be calling it before the solver has had a chance to initialize itself and loaded the actor.

Either check actor.isLoaded to see if the actor has been added to the solver, or call it on actor.OnBlueprintUnloaded() instead.

kind regards,
The particle is active in Start because i print various debug messages there to check if the blueprint is there and how to access it.
I found this problem with the teleport function in various occasion. Also the fact that i am changing the elastic global position using its transform instead of the Teleport() is because i noticed it was not working when i used it.

I actually use the teleportparticle also in start and the postion is changed if i reprint it but it is not physically moving.

i was thinking if it was possible to create in advance a new blueprint with the positions i want and then upload it. I tried to look around on how to do that but i don't know how to call the blueprint saved in memory
Reply
#4
(Today, 10:26 AM)alicecatalano Wrote: The particle is active in Start

I was not referring to the particle being active/inactive, but whether the actor has already been loaded by the solver or not.

(Today, 10:26 AM)alicecatalano Wrote: I found this problem with the teleport function in various occasion.

All the teleport function does is set solver.positions[particleIndex] to the value you pass to it, and solver.velocities[particleIndex] to zero. As long as the solver contains valid information at the time of calling the function it should work.

You can try calling solver.positions[82] = new Vector3(1,3,5); instead. It will result in an IndexOutOfBounds exception in case the solver does not yet contain particle #82.

Note that calling elastic.blueprint.positions[82] (as in your script's commented out line) won't do anything at runtime, as it's modifying blueprint data.

kind regards
Reply