Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Controlling specific particle force / custom constraints.
#11
This is a very cool implementation, just wondering if you had any advice on how to handle the crash that happens every time the snake hits a softbody object?
Reply
#12
(26-07-2021, 04:35 PM)PossPoss Wrote: This is a very cool implementation, just wondering if you had any advice on how to handle the crash that happens every time the snake hits a softbody object?

Hi there!

I assume you've installed both ObiRope and ObiSoftbody in the same project, correct? Can you share the crashlog of this crash you're experiencing?

kind regards,
Reply
#13
I've narrowed down the steps to reproduce into
1. Start a fresh project with just OBI
1. Go to the softbody example dragon scene, copy the dragon and skin 
2. Go to the rope example snake scene, past the dragon and skin under the obi solver
3. Ensure the dragon is inside the environment bounds and the particle picker has the solver set
4. Play the game and move the worm into the dragon 
5. Crash 

The error it gives is 

IndexOutOfRangeException: Index was outside the bounds of the array.
SnakeController.AnalyzeContacts (System.Object sender, Obi.ObiSolver+ObiCollisionEventArgs e) (at Assets/Obi/Samples/RopeAndRod/SampleResources/Scripts/SnakeController.cs:61)
Obi.ObiSolver.EndStep (System.Single substepTime) (at Assets/Obi/Scripts/Common/Solver/ObiSolver.cs:1598)
Obi.ObiUpdater.EndStep (System.Single substepDeltaTime) (at Assets/Obi/Scripts/Common/Updaters/ObiUpdater.cs:92)
Obi.ObiFixedUpdater.FixedUpdate () (at Assets/Obi/Scripts/Common/Updaters/ObiFixedUpdater.cs:52)

Line 61 is where you set the traction within Analyze Contacts, so my running theory is snake feet don't like touching dragon skin.
Reply
#14
That isn't a crash (as in Unity didn't close, right?), but an exception.

This is due to the snake sample scene not being designed with softbody interaction in mind, so it doesn't handle calculating traction against other actors. It assumes there's only a snake in the scene, as it is written ad-hoc for this specific example. You can modify the sample script (SnakeController) to add support for this, in case you need:

Line 61 reads:
Code:
traction[particleInActor.indexInActor] = 1;

There's only one traction array, and its length is equal to the amount of particles in the snake (line 22):

Code:
traction = new float[rope.activeParticleCount];

So when you add a softbody to the scene, particleInActor.indexInActor can be larger than the amount of particles in the snake (since the script assumes there's only one snake) thus throwing an out of bounds access exception.

It should be simple to fix, just check:

Quote:if (particleInActor.actor == rope)

To make sure the particle belongs to the snake, before accessing the traction array. Should look like this:

Code:
private void AnalyzeContacts(object sender, ObiSolver.ObiCollisionEventArgs e)
    {
        // iterate trough all contacts:
        for (int i = 0; i < e.contacts.Count; ++i)
        {
            var contact = e.contacts.Data[i];
            if (contact.distance < 0.005f)
            {
                int simplexIndex = solver.simplices[contact.bodyA];
                var particleInActor = solver.particleToActor[simplexIndex];

                if (particleInActor.actor == rope)
                {
                    // using 1 here, could calculate a traction value based on the type of terrain, friction, etc.
                    traction[particleInActor.indexInActor] = 1;

                    // accumulate surface normal:
                    surfaceNormal[particleInActor.indexInActor] += (Vector3)contact.normal;
                }
            }
        }
    }

Note it is your responsibility to modify sample scripts to work in the context of your game and fit your specific needs, as they're only that: samples Guiño.
Reply
#15
So when you add a softbody to the scene, particleInActor.indexInActor can be larger than the amount of particles in the snake 

Oooohhh of course, i should have seen that! 


it is your responsibility to modify sample scripts  

Absolutely, i simplified the issue i was having down to just the sample scripts to make it easy to reproduce. I've got a set of projects with different spline and softbody implementations, i'd just seen the snake not work when i brought it into a softbody scene and assumed it was the contact not recording, hadn't tweaked to traction being a finite list.  

Thanks for your help mate 
Reply
#16
No worries, you're welcome! Sonrisa Let me know if you need help at any point.
Reply
#17
Hi Jose!
Would it be possible to use this implementation with a custom 3D mesh?
This question applies to all ObiRope uses, does it need to be a ObiRopeExtrudedRenderer baked mesh?

I tried creating a snake with ObiBone on the first segment of the tail, but the snake became possessed each time the Root Rigidbody was set to isKinematic = false Gran sonrisa . Also, the tail was sliding on the ground, not keeping the snake's path so your implementation seems better.
Reply
#18
(19-06-2022, 03:09 PM)MoonglowStudio Wrote: Hi Jose!
Would it be possible to use this implementation with a custom 3D mesh?
This question applies to all ObiRope uses, does it need to be a ObiRopeExtrudedRenderer baked mesh?

Hi!

No, there's 4 built-in renderer components, and you can write your own too:
http://obi.virtualmethodstudio.com/manua...modes.html

not limited to ObiRopeExtrudedRenderer by any means Sonrisa. You can use ObiRopeMeshRenderer to render the rope using custom mesh.

(19-06-2022, 03:09 PM)MoonglowStudio Wrote: I tried creating a snake with ObiBone on the first segment of the tail, but the snake became possessed each time the Root Rigidbody was set to isKinematic = false Gran sonrisa . Also, the tail was sliding on the ground, not keeping the snake's path so your implementation seems better.

ObiBones aren't really meant for this use case. ObiRope with a custom renderer might be a better option, if ObiRopeExtrudedRenderer does not fit your requirements (for instance, you need the mesh to have joint-based animation as well) then you can just drive custom joints in your mesh using particle positions.
Reply
#19
Thanks for answering so fast!
1. I tried it and it seems to work quite well. My only issue is that the original mesh has multiple meshes and a simple animation for the snake's ondulation and tongue hissing.
I guess if I want to use an Animator and a complex mesh, the only possible use is ObiBone?
I don't need complex movement, just a snake that passes through and hisses sometimes, and the body should collide with floor for realism.

2. Also, with ObiBone, when the Solver is at the Armature's root, even with World inertia settings maxed out, there is no movement applied to ObiBone when I move the parent mesh object manually. Is it intended as it works with the Animator, not Transform?
I got around it by putting the solver on an empty parent of the Animator, then manual movement of the Animator transform applies to the simulation.
Reply
#20
(20-06-2022, 04:46 PM)MoonglowStudio Wrote: Thanks for answering so fast!
1. I tried it and it seems to work quite well. My only issue is that the original mesh has multiple meshes and a simple animation for the snake's ondulation and tongue hissing.
I guess if I want to use an Animator and a complex mesh, the only possible use is ObiBone?

Out of the box, yes your only option is ObiBone if you have a complex joint hierarchy with pre-existing animation. However with some simple scripting, you can drive custom joints using particle data: http://obi.virtualmethodstudio.com/manua...icles.html

(20-06-2022, 04:46 PM)MoonglowStudio Wrote: 2. Also, with ObiBone, when the Solver is at the Armature's root, even with World inertia settings maxed out, there is no movement applied to ObiBone when I move the parent mesh object manually. Is it intended as it works with the Animator, not Transform?

Simulation happens in solver space. Which means that if you move anything other than the solver transform (or anything above it in the hierarchy) or the bones involved in the simulation, it will be ignored.
Reply