Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Finding last point of rope
#31
Hi, I am not professional programmer and I use Playmaker and bolt but if I am good at programming I could have made my own rope , I bought this rope asset because from the video and its description it shows my need quite easily, which it is but i didn't know it needs complex understanding level, thats why I am asking for help. I believe most people dont buy if they are good at something.  Tímido

Coming to my issue, i did what you did, it still attaches the torn part around somewhere and stretches weirdly. Could you check?
Reply
#32
(19-11-2021, 01:39 PM)srid96 Wrote: I am not professional programmer, if I am good at programming I could have made my own rope , I bought this rope asset because from the video and its description it shows my need quite easily, which it is but i didn't know it needs complex understanding level, thats why I am asking for help.

Hi!

We're talking about writing "if" conditionals and iterating trough lists here, which is far from being complex or requiring professional skills. Having basic understanding of C# syntax and writing something like Obi are two very different things. It took around 7 years of working 8 hours a day to write Obi, even with a lot of physics and math background.

I can't be a personal programming teacher to every Obi user, not because I dislike it (I love programming and love helping others) but because it is unsustainable from a time management perspective. If I offered this level of support to everyone I'd be out of business in less than a month. Hope you understand. Basic programming skills are required to be able to use Obi, as stated in our FAQ:

http://obi.virtualmethodstudio.com/faq.html
Quote:Is scripting / coding required to use Obi?

For anything except the bare basics, yes. Obi is written in HPCS (high performance C#) and C++11, and it exposes a C# API. Obi deals with hundreds of particles and thousands of constraints every frame. These are exposed to you, the user, so learning how to write performant code is a prerequisite.



Quote:I believe most people dont buy if they are good at something.  Tímido

Do mechanical engineers build their own cars instead of buying them? Do game developers make their own rendering pipeline, physics engine, input manager, audio system, etc or do they just use an existing game engine/middleware? Guiño

(19-11-2021, 01:39 PM)srid96 Wrote: Coming to my issue, i did what you did, it still attaches the torn part around somewhere and stretches weirdly. Could you check?

I tested the script and it works perfectly. Here's a video of the results and the full script:



Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;

[RequireComponent(typeof(ObiSolver))]
public class CutRope : MonoBehaviour
{
    ObiSolver solver;

    void Awake()
    {
        solver = GetComponent<Obi.ObiSolver>();
    }

    void OnEnable()
    {
        solver.OnCollision += Solver_OnCollision;
    }

    void OnDisable()
    {
        solver.OnCollision -= Solver_OnCollision;
    }

    void Solver_OnCollision(object sender, ObiSolver.ObiCollisionEventArgs e)
    {
        var world = ObiColliderWorld.GetInstance();

        // just iterate over all contacts in the current frame:
        foreach (Oni.Contact contact in e.contacts)
        {
            // if this one is an actual collision:
            if (contact.distance < 0.01)
            {
                ObiColliderBase col = world.colliderHandles[contact.bodyB].owner;
                if (col != null)
                    TearRope(col, contact);
            }

        }
    }

    private void TearRope(ObiColliderBase col, Oni.Contact contact)
    {
        if (!col || !col.CompareTag("Saw")) return;

        // 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:
        bool torn = false;
        List<ObiStructuralElement> toDestroy = new List<ObiStructuralElement>();
        foreach (var elm in actor.elements)
        {

            if (elm.particle1 == particleIndex)
            {
                actor.Tear(elm);
                torn = true;
            }

            // deactivate particles of all elements after the torn one:
            if (torn)
            {
                actor.DeactivateParticle(solver.particleToActor[elm.particle1].indexInActor);
                actor.DeactivateParticle(solver.particleToActor[elm.particle2].indexInActor);
                toDestroy.Add(elm);
            }
        }

        // remove all elements past the torn one:
        foreach (var elm in toDestroy)
            actor.elements.Remove(elm);

        // update constraints:
        if (torn)
            actor.RebuildConstraintsFromElements();

    }

}
Reply
#33
Thanks, am learning as you already know. I didn't see the FAQ section, thanks for helping out.
Reply