Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  How to attach a GameObject to a rope from script?
#3
(09-06-2021, 08:24 AM)josemendez Wrote: You can't create a control point at runtime. Or rather, it won't have any effect. Blueprints behave just like prefabs: once you instantiate a prefab, the instance will no longer be affected by changes made to the prefab. It's a "snapshot" of the prefab at the moment of instantiating it. Similarly, once you create an actor out of a blueprint, modifying the blueprint has no effect on the actor/actors instantiated from it.

Control points only exist in blueprints, to aid you in setting the initial shape and properties of the rope. At runtime, actors only contain particles and constraints.


You're retrieving the position of the rope actor:

Code:
solver.particleToActor[contact.bodyA].actor.transform.position;

You want the position of the particle that has collided, so use this instead:

Code:
solver.positions[solver.simplices[contact.bodyA]];

See:
http://obi.virtualmethodstudio.com/tutor...sions.html



Because that particle does not exist. You've regenerated the blueprint, but as I explained that does not change any existing ropes in the scene. In addition to thisĀ  you're accessing the groups array using a particle index, which does not make any sense (can result in out of bounds access exceptions):

Code:
attachment.particleGroup = blueprint.groups[particleIndex];

Should be:

Code:
attachment.particleGroup = blueprint.groups[groupIndex];

If your blueprint has 3 control points, "groupIndex" can only be 0, 1, or 2.



If you want two-way coupling between the rope and the object, you can create a new pin constraint at runtime. That's the simplest way. See adding/removing constraints in the "scripting constraints" section of the manual:

http://obi.virtualmethodstudio.com/tutor...aints.html

Internally, this is what a dynamic attachment does: it creates a pin constraint between the particle index corresponding to a control point, and a target object.
Thanks for your reply.
pin constraint works exactly as what I need.

But, after the gameobjet is attached to the rope, the rope is moving slightly.
The attached gameobject is rigidbody.
Before attaching, the rope is static perfectly.
How do I make the rope be in static after attaching rigidbody objects?
Reply


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