Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  problem of particle position
#1
Hi bro.
I make a rope and move it in runtime.
Now,i want to get some particles world position but i failed.

I use   
Code:
actorIndex = rope.blueprint.groups[0].particleIndices[0]
to get actor index of this particle.

And i use
Code:
solverIndex = actor.solverIndices[actorIndex]
to get solver index of this particle

Finally,i use
Code:
position = actor.GetParticlePosition(solverIndex);
to get world position of this particle

Problem is this position is not change when i move rope, so i think maybe it is a local position.
Could you help me to get world position of particle?
Think you,waiting for you repose.
Reply
#2
Hi there,

Works fine for me, using the exact same code you posted:

Code:
using UnityEngine;
using Obi;

[RequireComponent(typeof(ObiActor))]
public class GetCPPosition : MonoBehaviour
{
    ObiActor actor;
    public int cpIndex = 0;

    void Start()
    {
        actor = GetComponent<ObiActor>();
    }

    private void OnValidate()
    {
        cpIndex = Mathf.Max(0, cpIndex);
    }

    void OnDrawGizmos()
    {
        if (actor != null &&
            actor.blueprint != null &&
            actor.blueprint.groups.Count > cpIndex &&
            actor.blueprint.groups[cpIndex].particleIndices.Count > 0)
        {
            int actorIndex = actor.blueprint.groups[cpIndex].particleIndices[0];
            int solverIndex = actor.solverIndices[actorIndex];
            Gizmos.DrawSphere(actor.GetParticlePosition(solverIndex), 0.5f);
        }
    }
}
Reply
#3
Hi,it ‘s me
Is the particle's world position are calculated by   rope.gameObject.transform?
Because I use particleAttachment connect a particle group to the rope self, i move rope's position to move particles

set like this:
Code:
rope.GetComponents<ObiParticleAttachment>()[0].target = rope.gameObject.transform;
rope.GetComponents<ObiParticleAttachment>()[0].particleGroup = blueprint.groups[0];
move like this:
Code:
Vector3 to_new_position = new Vector3(0.0f, 0.0f, 1.0f);
rope.gameObject.transform.Translate(to_new_position, Space.World);
Reply
#4
(23-12-2020, 03:04 PM)FZMv587 Wrote: Hi,it ‘s me
Is the particle's world position are calculated by   rope.gameObject.transform?
Because I use particleAttachment connect a particle group to the rope self, i move rope's position to move particles

set like this:
Code:
rope.GetComponents<ObiParticleAttachment>()[0].target = rope.gameObject.transform;
rope.GetComponents<ObiParticleAttachment>()[0].particleGroup = blueprint.groups[0];
move like this:
Code:
Vector3 to_new_position = new Vector3(0.0f, 0.0f, 1.0f);
rope.gameObject.transform.Translate(to_new_position, Space.World);

Particles are simulated in solver space. To convert to world-space, they're transformed using the solver's transform.

When you attach a particle to a target transform, the particle position at the time of setting the attachment's target/particleGroup is stored expressed in the target's local space. At runtime, this target-space position is converted to solver space and used to set the particle's position. Hope this makes sense!
Reply