25-02-2020, 08:04 PM
(This post was last modified: 25-02-2020, 08:17 PM by VirtualCucumber.)
Just hopped back on this project and still wondering how to attach at runtime.
The rope just has ObiAttachment and AttachRuntime component on it, the solvers gravity is set to 0 and the collision phases on particles and object are the same for no collisions.
AttachRuntime.cs:
The result is in the gif. I did try to force the position to the attachmentObject position but as soon as you reset the mass back to default it snaps back to the position in the gif:
The rope just has ObiAttachment and AttachRuntime component on it, the solvers gravity is set to 0 and the collision phases on particles and object are the same for no collisions.
AttachRuntime.cs:
Code:
using UnityEngine;
using Obi;
public class AttachRuntime: MonoBehaviour
{
public ObiRope rope;
public ObiParticleAttachment attachment;
public Transform attachmentObject;
private PlayerActions _input;
private void Start()
{
_input = PlayerActions.CreateWithDefaultBindings();
}
private void Update()
{
if (_input.Interact.WasPressed)
{
attachment.target = attachmentObject;
}
}
}
The result is in the gif. I did try to force the position to the attachmentObject position but as soon as you reset the mass back to default it snaps back to the position in the gif:
Code:
attachment.target = attachmentObject;
var index = rope.solverIndices[0];
var targetPos = rope.solver.transform.InverseTransformPoint(attachmentObject.position);
rope.solver.invMasses[index] = 0f;
rope.solver.positions[index] = targetPos;
rope.solver.invMasses[index] = 0.1f;