Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Linking the positions of actors and other objects
#1
Currently, I'm trying to place an empty object in each of the two Obi Rope's approximate centers in the same solver.

Hierarchy is as follows.
Code:
□Obi Solver
  -rope1
  -rope2
□pointObject1
□pointObject2

The following script is pasted on each rope.
Code:
ObiActor actor;
public GameObject pointObject;
int ropeCenterIndex;

void Awake()
{
  actor = this.gameObject.GetComponent<ObiActor>();
  ropeCenterIndex = actor.solverIndices.Length / 2;
}

void Update()
{
  var position = actor.solver.positions[ropeCenterIndex];
  pointObject.transform.position = new Vector3(position.x,
  position.y,
  position.z);
}


For the "public GameObject pointObject" part, I manually put pointObject1 in rope1 and pointObject2 in rope2 from the Inspector.

When this is done, the center of rope2 and pointObject1 will move in tandem, and pointObject2 will not move from its original position, which is a strange state.

How can I get each pointObject to work with the center of each rope?


Sorry for always a beginner question.

Thank you.
Reply
#2
Hi there!

You're accessing the same particle for both ropes:
Code:
var position = actor.solver.positions[ropeCenterIndex];

To picture why this is wrong, let's pretend each rope has 10 particles. The first rope uses particles 0-9 in the solver, and the second one uses particles 10-19. Remember that each actor contains the indices of its particles in the solverIndices array, so the solverIndices array will contain values 0-9 for the first particle and 10-19 for the second one.

ropeCenterIndex will be 10/2 = 5, for both ropes. You're accessing the particle at position 5 in the solver, which belongs to the first rope. So both ropes will access the same particle (5), since ropeCenterIndex has the same value for both ropes.

you want to do this instead:
Code:
var position = actor.solver.positions[actor.solverIndices[ropeCenterIndex]];

This way, the first rope accesses particle 4, and the second rope accesses particle 14. Does this make sense?

cheers!
Reply
#3
Thank you for your polite reply!

It worked perfectly.
Thank you very much.
Reply