Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scripting Questions
#1
I am using parts of grappling hook to create rope.

********************************
How do you make sure the particles are turned on.  The obi Solver shows 0 particles.

********************************
When you are moving the end of rope, how do you FREEZE start/end prefab.  They tend to juggle around.

Is there a script that forces the object to follow the camera?

********************************

What is the best way to prevent wires from clipping through walls.

what about setting the obi collider thickness to 0.1?
Reply
#2
(13-09-2017, 05:11 AM)Parker Wrote: I am using parts of grappling hook to create rope.

********************************
How do you make sure the particles are turned on.  The obi Solver shows 0 particles.

********************************
When you are moving the end of rope, how do you FREEZE start/end prefab.  They tend to juggle around.

Is there a script that forces the object to follow the camera?

********************************

What is the best way to prevent wires from clipping through walls.

what about setting the obi collider thickness to 0.1?

Hi there,

I'm not quite sure I understand your questions, lets see:

1.- How do you make sure the particles are turned on.  The obi Solver shows 0 particles.
Under what circumstances? if your solver is not managing any actor, it will show 0 particles used. Also if your actor requires more particles that the "max particles" setting on the solver, it will not be able to manage that particular actor and show 0 particles used. (All of this supposing you've assigned a solver to at least some actor(s) in your scene).

2.-When you are moving the end of rope, how do you FREEZE start/end prefab.  They tend to juggle around.
Well, if by juggle you mean "twist", this is because ObiRope does not simulate torsion (twisting along the main rope axis) forces. Because of this, there's no control over twisting motion at any point of the rope. This is usually too expensive/unstable to calculate properly, and not that useful for games.

Note however that if you refer just to overall movement, this is to be expected since they follow the rope ends, to which they're attached.

3.- Is there a script that forces the object to follow the camera?
No, not included. You're supposed to write such simple things yourself Guiño

4.- What is the best way to prevent wires from clipping through walls.
Under normal circumstances, this should be achieved by just enabling collisions in your solver. Also avoid translating MeshColliders at runtime using their transform.
Reply
#3
How can I update a rope after I change the material or the end.  If I am running a level, and I click on the initialize button, the rope will freeze.

If I use the code from the grappling hook, the rope ends, get pinned.  Sample code below.

I need to update the rope in runtime and have it keep settings.

#2) what is "avoid translating MeshColliders at runtime using their transform."  Do u have better description or screen shot?

#3) Is there an easy way in code to set phase?  I would like to set all of the particles to int X on a rope.


public ObiRope rope;
public ObiRope Rope = new ObiRope();
public ObiSolver Solver = new ObiSolver();
public Material ColorMat = new Material("");
public ObiCatmullRomCurve Curve = new ObiCatmullRomCurve();
public ObiRopeCursor Cursor = new ObiRopeCursor();

void MakeRope()
{
    if (Rope == null)
        Rope = gameObject.AddComponent<ObiRope>();

    if (Curve == null)
    {
        Curve = gameObject.AddComponent<ObiCatmullRomCurve>();
        Rope.ropePath = Curve;
    }
    if (Solver == null)
    {
        Solver = gameObject.AddComponent<ObiSolver>();
        Rope.Solver = Solver;
    }

    // Provide a solver and a curve:
    Rope.GetComponent<MeshRenderer>().material = ColorMat;

    //Configure rope and solver parameters:
    Rope.SectionThicknessScale = 0.10f;
    Rope.resolution = 1f;
    Rope.BendingConstraints.stiffness = 0.2f;
    Rope.UVScale = new Vector2(1, 5);
    Rope.NormalizeV = false;
    Rope.UVAnchor = 1;

    Rope.RestLength = 10;
    Solver.distanceConstraintParameters.iterations = 15;
    Solver.pinConstraintParameters.iterations = 15;
    Solver.bendingConstraintParameters.iterations = 1;

    //Add a cursor to change rope length:
    Cursor = Rope.gameObject.AddComponent<ObiRopeCursor>();
    Cursor.rope = Rope;
    Cursor.normalizedCoord = 0;
    Cursor.direction = true;
}
 
public void UpdateRope()
{
    StartCoroutine(CreateRope());
}
private IEnumerator CreateRope()
{
    yield return rope.GeneratePhysicRepresentationForMesh();
}
Reply
#4
Hi,


Quote:How can I update a rope after I change the material or the end.  If I am running a level, and I click on the initialize button, the rope will freeze.


This is the expected behavior. Initializing a rope re-creates it from scratch:

1.- Deletes all its particles and constraints from the solver, resets all per-particle properties to its default values (a warning dialog pops up telling you this when clicking the button).
2.- Generates new particles and constraints based on the spline curve.

This of course means that the rope needs to be re-added to a solver after initializing, as it is a "new rope" so to speak. Initializing a rope should generally only be done in the editor, or just once at runtime.

Changing the material or the prefab at the end should just work. No need to re-initialize the rope after changing them.


Quote:I need to update the rope in runtime and have it keep settings.

If by "update" you mean reinitializing it, it's just not possible. Reinitializing a rope clears all its properties and generates a new rope from scratch. 
Depending on what you're trying to accomplish, it should be easier to just modify the parameters you need at runtime. I see no need to reinitialize a rope at runtime, except for very specific use cases.


Quote:what is "avoid translating MeshColliders at runtime using their transform."  Do u have better description or screen shot?

I mean, do not move a MeshCollider around by doing collider.transform.position = whatever. This essentially "teleports" the collider around, which can cause particles to pass trough it or get stuck inside it since continuous collision detection will only work with rigidbodies. Either use a rigidbody, or if you cannot afford to apply physics to a MeshCollider, use primitive colliders instead.

Rigidbodies have velocity, transforms do not. Continuous collision detection needs to know the velocity of all objects involved in a collision to be able to resolve it. If these velocities are not available, the system falls back to static collision detection (which is very prone to the bullet-trough-paper problem, aka "tunneling").


Quote:Is there an easy way in code to set phase?  I would like to set all of the particles to int X on a rope.

Yes, just do:

Code:
for (int i = 0; i < rope.TotalParticles; ++i)
    rope.phases[i] = Oni.MakePhase(X,rope.selfCollisions?Oni.ParticlePhase.SelfCollide:0);
rope.PushDataToSolver(ParticleData.PHASES);
   
Reply
#5
Thanks, great info.

*************************************
My questions will relate to the code I posted.
*************************************

1) When I change the rope ends using code, the rope does not show the changes and keeps old ends.

What code can I use to force the rope to "update/show" new ends. Update means refresh the rope with new values.

2) When I use code to put ends on the rope, the ends do not move with the rope. The rope moves, but the ends do not.

3) When creating ends, should I use a prefab or create a object in scene to use as ends.

If I need to create object what should be done with the new object object the rope gets its ends.
If I use a prefab, how can I change material on one item and not have all ropes change material.

4) When I use code to create a rope the rope lies flat on the script, no physics. I cannot pin ends and have
the rope swing. Is there code to wake up the rope?

5) When I use the code to create a rope, the solver shows 0 particles.
Reply
#6
I think what would really help is a sample script that can be used while Unity is running in real time is a sample script.

Include the ability to create a rope, initialize it,
update ends,
adjust length

have it run in real time.
Reply
#7
I did stumble on this code to initialize the rope during runtime.  After my rope is created, I would call InitTheRope();

    private IEnumerator InitRope()
    {
        yield return rope.GeneratePhysicRepresentationForMesh();
    }
 
    public void InitTheRope()
    {
        StartCoroutine(InitRope());
    }


To get this to work, I had to update some code, ObiBoneEditor.cs

change line 150 & 159 from

EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());

to

if (!Application.isPlaying) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());


To get the rope to update will the application is running, I used this code.

public void RefreshTheRope()
{
    ObiRope rope = gameObject.GetComponent<ObiRope>();
    rope.OnEnable();
}
Reply