Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Assigning target to ParticleAttchment component at runtime
#8
Just hopped back on this project and still wondering how to attach at runtime.

[Image: dt7D3Hz.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;
Reply


Messages In This Thread
RE: Assigning target to ParticleAttchment component at runtime - by VirtualCucumber - 25-02-2020, 08:04 PM