22-11-2021, 11:24 AM (This post was last modified: 22-11-2021, 11:26 AM by greyhawk.)
Greetings,
How do you think I can supply the damaged rope in the picture with obi rope? Should I find the relevant particle and place a 3d object with this appearance on it? I am open to your suggestions.
22-11-2021, 11:33 AM (This post was last modified: 22-11-2021, 11:35 AM by josemendez.)
(22-11-2021, 11:24 AM)greyhawk Wrote: Greetings,
How do you think I can supply the damaged rope in the picture with obi rope? Should I find the relevant particle and place a 3d object with this appearance on it? I am open to your suggestions.
Note this would just give you a position to place the object at, not an orientation (remember that ropes do not model torsion, unlike rods).
You could also just determine the damaged zone using a normalized coordinate from 0 (start of the rope) to 1 (end of the rope) and use pathSmoother.GetSectionAt(coordinate). This returns an orthonormal frame, complete with position and orientation - in case of ropes, since the simulation does not output an orientation, orientation is determined using parallel transport.
There's a utility script included that will place an object at a normalized position in the rope using GetSectionAt:
/Obi/Scripts/RopeAndRod/Utils/ObiRopeAttach.cs
Note this would just give you a position to place the object at, not an orientation (remember that ropes do not model torsion, unlike rods).
You could also just determine the damaged zone using a normalized coordinate from 0 (start of the rope) to 1 (end of the rope) and use pathSmoother.GetSectionAt(coordinate). This returns an orthonormal frame, complete with position and orientation - in case of ropes, since the simulation does not output an orientation, orientation is determined using parallel transport.
There's a utility script included that will place an object at a normalized position in the rope using GetSectionAt:
/Obi/Scripts/RopeAndRod/Utils/ObiRopeAttach.cs
How can I get the coordinate you mentioned when an object touches the area I want to damage?
(22-11-2021, 01:15 PM)josemendez Wrote: Simply divide the index of the particle (or element) by the amount of particles or elements in the rope.
Hi, its me again.
I didn't want to open a separate post because the problem I'm having now is after the solution here. I am experiencing the error in the image when I cut the rope after placing the object showing the damage. do you have a suggestion? Due to this error, the damaged object does not follow the rope.
(22-11-2021, 03:40 PM)greyhawk Wrote: Hi, its me again.
I didn't want to open a separate post because the problem I'm having now is after the solution here. I am experiencing the error in the image when I cut the rope after placing the object showing the damage. do you have a suggestion? Due to this error, the damaged object does not follow the rope.
This can only happen if the constraints are still in a dirty state (ie, the amount of elements in the rope and constraints the solver don't match.)
Are you rebuilding the constraints after cutting the rope? Can you share your code for tearing the rope?
(22-11-2021, 04:05 PM)josemendez Wrote: This can only happen if the constraints are still in a dirty state (ie, the amount of elements in the rope and constraints the solver don't match.)
Are you rebuilding the constraints after cutting the rope? Can you share your code for tearing the rope?
Here my code:
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;
namespace _Game.Scripts.Entities.Rope
{
[RequireComponent(typeof(ObiSolver))]
public class RopeCutter : MonoBehaviour
{
private ObiSolver solver;
private ObiRope currentRope;
public GameObject damagezone;
private void DamageRope(ObiColliderBase col, Oni.Contact contact)
{
// get the particle index:
int particleIndex = solver.simplices[contact.bodyA];
// retrieve the actor this particle belongs to:
ObiSolver.ParticleInActor pa = solver.particleToActor[particleIndex];
var actor = pa.actor as ObiRope;
// not a rope, stop:
if (actor == null) return;
float i = -1;
// check rope elements and tear the one that references this particle:
foreach (var elm in actor.elements)
{
i++;
if (elm.particle1 == particleIndex)
{
if (actor!=currentRope)
{
var obj = Instantiate(damagezone);
obj.GetComponent<ObiRopeAttach>().m = i / actor.elements.Count;
obj.GetComponent<ObiRopeAttach>().generator = actor.GetComponent<ObiPathSmoother>();
obj.GetComponent<ObiRopeAttach>()._continue = true;
//actor.Tear(elm);
StartCoroutine(ReservationRope(actor));
}
break;
}
}
}
private void TearRope(ObiColliderBase col, Oni.Contact contact)
{
// get the particle index:
int particleIndex = solver.simplices[contact.bodyA];
// retrieve the actor this particle belongs to:
ObiSolver.ParticleInActor pa = solver.particleToActor[particleIndex];
var actor = pa.actor as ObiRope;
// not a rope, stop:
if (actor == null) return;
// check rope elements and tear the one that references this particle:
foreach (var elm in actor.elements)
{
if (elm.particle1 == particleIndex)
{
actor.Tear(elm);
actor.GetComponent<RopeController>().OnRopeTear();
actor.RebuildConstraintsFromElements();
(22-11-2021, 04:05 PM)josemendez Wrote: This can only happen if the constraints are still in a dirty state (ie, the amount of elements in the rope and constraints the solver don't match.)
Are you rebuilding the constraints after cutting the rope? Can you share your code for tearing the rope?