Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  How to attach a GameObject to a rope from script?
#7
(14-06-2021, 08:11 AM)josemendez Wrote: You're passing Vector3.zero as the pin offset. This means the pinned particle will shift to the exact center of the rigidbody as soon as you activate the constraint.

Pass the current particle's position in local space instead, so that it doesn't move. Something like this:
Code:
var localPos = body.transform.InverseTransformPoint(solver.transform.TransformPoint(solver.positions[index]));

Remember that Unity's TransformPoint/Vector/Direction and InverseTransformPoint/Vector/Direction let you convert data from local to world space and vice-versa. You should get very comfortable with these:
https://docs.unity3d.com/ScriptReference...Point.html
https://docs.unity3d.com/ScriptReference...Point.html
Thank you. It works for me.

Now I attached some cubes onto the rope. And when I move the rope, sometimes some attached cubes will change its relative position to the rope.

For example, a cube is attached onto the left side of a rope. If I change the position of the rope, sometimes the position of the cube is changed to the right side of the rope. And seems the position of the cube is changed not the same frame of the rope, more like following. Because I can see the following animation.

Is it possible to make the relative position of the cube and the rope be static?
And update the position of the rope and cube at the same frame?
Reply


Messages In This Thread
RE: How to attach a GameObject to a rope from script? - by wakin001 - 16-06-2021, 03:50 PM