private void Start() { // Get the rigidbody on this game object rb = GetComponent <Rigidbody>(); // Initializes an empty game object that tracks the // camera Y angle for player movement direction cameraAngle = GameObject.Find("GetsCameraYAngle"); cam = Camera.main.gameObject; gameManager = GameManager.instance; audioManager = AudioManager.instance; rope = scarfController.gameObject.GetComponent <ObiRope>(); pickupCont = GetComponent <PickupController>(); // Find all outline scripts m_Outlines = GetComponentsInChildren <Outline>(); // Disable them at start foreach (Outline outline in m_Outlines) { outline.enabled = false; } meowSound = GetComponent <AudioSource>(); }
void Awake() { // Create both the rope and the solver: rope = gameObject.AddComponent <ObiRope>(); curve = gameObject.AddComponent <ObiCatmullRomCurve>(); solver = gameObject.AddComponent <ObiSolver>(); // Provide a solver and a curve: rope.Solver = solver; rope.ropePath = curve; rope.GetComponent <MeshRenderer>().material = material; // Configure rope and solver parameters: rope.resolution = 0.1f; rope.BendingConstraints.stiffness = 0.2f; rope.UVScale = new Vector2(1, 5); rope.NormalizeV = false; rope.UVAnchor = 1; 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; }
void Awake() { // Create both the rope and the solver: rope = gameObject.AddComponent <ObiRope>(); curve = gameObject.AddComponent <ObiCatmullRomCurve>(); solver = gameObject.AddComponent <ObiSolver>(); // Provide a solver and a curve: rope.Solver = solver; rope.ropePath = curve; rope.GetComponent <MeshRenderer>().material = material; // Configure rope and solver parameters: rope.resolution = 0.1f; rope.BendingConstraints.stiffness = 0.2f; rope.uvScale = new Vector2(1, 5); rope.normalizeV = false; rope.uvAnchor = 1; solver.substeps = 3; solver.distanceConstraintParameters.iterations = 5; solver.pinConstraintParameters.iterations = 5; solver.bendingConstraintParameters.iterations = 1; solver.particleCollisionConstraintParameters.enabled = false; solver.volumeConstraintParameters.enabled = false; solver.densityConstraintParameters.enabled = false; solver.stitchConstraintParameters.enabled = false; solver.skinConstraintParameters.enabled = false; solver.tetherConstraintParameters.enabled = false; // Add a cursor to be able to change rope length: cursor = rope.gameObject.AddComponent <ObiRopeCursor>(); cursor.normalizedCoord = 0; cursor.direction = true; }
void Start() { thrower = GetComponent <Thrower>(); cursor = GetComponent <ObiRopeCursor>(); rope = cursor.GetComponent <ObiRope>(); hook.grapple = this; StartCoroutine(RetrieveGrappleIE()); }
private void PinRope(ObiRope rope, ObiCollider bodyA, ObiCollider bodyB, Vector3 offsetA, Vector3 offsetB) { // Pin both ends of the rope (this enables two-way interaction between character and rope): var pinConstraints = rope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints <ObiPinConstraintsBatch>; pinConstraints.Clear(); var batch = new ObiPinConstraintsBatch(); batch.AddConstraint(rope.solverIndices[0], bodyA, offsetA, Quaternion.identity, 0, 999, float.PositiveInfinity); batch.AddConstraint(rope.solverIndices[rope.activeParticleCount - 1], bodyB, offsetB, Quaternion.identity, 0, 999, float.PositiveInfinity); batch.activeConstraintCount = 2; pinConstraints.AddBatch(batch); }
/// <summary> /// Creates a straight rope anchored to a transform at the top. /// Transform may or may not move around and may or may not have a rigidbody. /// When you call this the rope will appear in the scene and immediately interact with gravity and objects with ObiColliders. /// Called from anywhere (main thread only) /// </summary> public IEnumerator MakeRope(Transform anchoredTo, Vector3 attachmentOffset, float ropeLength) { // create a new GameObject with the required components: a solver, a rope, and a curve. // we also throw a cursor in to be able to change its length. GameObject ropeObject = new GameObject("rope", typeof(ObiSolver), typeof(ObiRope), typeof(ObiCatmullRomCurve), typeof(ObiRopeCursor)); // get references to all components: rope = ropeObject.GetComponent <ObiRope>(); cursor = ropeObject.GetComponent <ObiRopeCursor>(); solver = ropeObject.GetComponent <ObiSolver>(); ObiCatmullRomCurve path = ropeObject.GetComponent <ObiCatmullRomCurve>(); // set up component references (see ObiRopeHelper.cs) rope.Solver = solver; rope.ropePath = path; rope.section = Resources.Load <ObiRopeSection>("DefaultRopeSection"); // set path control points (duplicate end points, to set curvature as required by CatmullRom splines): path.controlPoints.Clear(); path.controlPoints.Add(Vector3.zero); path.controlPoints.Add(Vector3.zero); path.controlPoints.Add(Vector3.down * ropeLength); path.controlPoints.Add(Vector3.down * ropeLength); rope.pooledParticles = 2000; // parent the rope to the anchor transform: rope.transform.SetParent(anchoredTo, false); rope.transform.localPosition = attachmentOffset; // generate particles/constraints and add them to the solver (see ObiRopeHelper.cs) yield return(rope.StartCoroutine(rope.GeneratePhysicRepresentationForMesh())); rope.AddToSolver(null); // get the last particle in the rope at its rest state. pinnedParticle = rope.UsedParticles - 1; // add a tethers batch: ObiTetherConstraintBatch tetherBatch = new ObiTetherConstraintBatch(true, false, 0, 1); rope.TetherConstraints.AddBatch(tetherBatch); //UpdateTethers(); // fix first particle in place (see http://obi.virtualmethodstudio.com/tutorials/scriptingparticles.html) rope.invMasses[0] = 0; Oni.SetParticleInverseMasses(solver.OniSolver, new float[] { 0 }, 1, rope.particleIndices[0]); }
private void Awake() { InteractableObjects = GetComponentsInChildren <VRTK_InteractableObject>(); obiRope = GetComponentInChildren <ObiRope>(); pinConstrain = GetComponentInChildren <ObiPinConstraints>(); pinConstraintBatch = pinConstrain.GetFirstBatch(); obiSolver = GetComponentInChildren <ObiSolver>(); UpdateIndex(); NameOfParticleLast = pinConstraintBatch.pinBodies[LastParticleConstrainIndex].gameObject.name; NameOfParticleFirst = pinConstraintBatch.pinBodies[FirstParticleConstrainIndex].gameObject.name; foreach (var interactObject in InteractableObjects) { interactObject.InteractableObjectGrabbed += InteractObject_InteractableObjectGrabbed; interactObject.InteractableObjectUngrabbed += InteractObject_InteractableObjectUngrabbed; } }
private void Start() { obiRope = transform.parent.GetComponentInChildren <ObiRope>(); pinConstrain = transform.parent.GetComponentInChildren <ObiPinConstraints>(); pinConstraintBatch = pinConstrain.GetFirstBatch(); obiSolver = transform.parent.GetComponentInChildren <ObiSolver>(); int LastParticleConstrainIndex = pinConstraintBatch.GetConstraintsInvolvingParticle(obiRope.UsedParticles - 1).Count != 0 ? pinConstraintBatch.GetConstraintsInvolvingParticle(obiRope.UsedParticles - 1)[0] : -1; int FirstParticleConstrainIndex = pinConstraintBatch.GetConstraintsInvolvingParticle(0).Count != 0 ? pinConstraintBatch.GetConstraintsInvolvingParticle(0)[0] : -1; if (gameObject == pinConstraintBatch.pinBodies[LastParticleConstrainIndex].gameObject) { particleIndexOne = obiRope.UsedParticles - 1; particleIndexTwo = particleIndexOne - 1; } else if (gameObject == pinConstraintBatch.pinBodies[FirstParticleConstrainIndex].gameObject) { particleIndexOne = 0; particleIndexTwo = 1; } else { particleIndexOne = -1; particleIndexTwo = -1; } if (m_Handle != null) { m_Handle.InteractableObjectUsed += M_Handle_InteractableObjectUsed; m_Handle.InteractableObjectUnused += M_Handle_InteractableObjectUnused; } UpdateIndex(); particleOffsetOne = pinConstraintBatch.pinOffsets[contraintIndexOne]; particleOffsetTwo = pinConstraintBatch.pinOffsets[contraintIndexTwo]; Debug.Log(particleOffsetOne); Debug.Log(particleOffsetTwo); GetComponent <MeshRenderer>().material.color = m_ColorInactive; }
void Awake() { // Create both the rope and the solver: rope = gameObject.AddComponent <ObiRope>(); ropeRenderer = gameObject.AddComponent <ObiRopeExtrudedRenderer>(); ropeRenderer.section = section; ropeRenderer.uvScale = new Vector2(1, 5); ropeRenderer.normalizeV = false; ropeRenderer.uvAnchor = 1; rope.GetComponent <MeshRenderer>().material = material; // Setup a blueprint for the rope: blueprint = ScriptableObject.CreateInstance <ObiRopeBlueprint>(); blueprint.resolution = 0.5f; // Tweak rope parameters: rope.maxBending = 0.02f; // Add a cursor to be able to change rope length: cursor = rope.gameObject.AddComponent <ObiRopeCursor>(); cursor.cursorMu = 0; cursor.direction = true; }
void Awake() { rope = GetComponent <ObiRope>(); localMaterial = GetComponent <MeshRenderer>().material; }
public IEnumerator MakeRope() { print("Load Extraction Rope"); ropeObject = new GameObject("rope", typeof(ObiSolver), typeof(ObiRope), typeof(ObiCatmullRomCurve), typeof(ObiRopeCursor)); // get references to all components: ObiSolver solver = ropeObject.GetComponent <ObiSolver>(); rope = ropeObject.GetComponent <ObiRope>(); ObiCatmullRomCurve path = ropeObject.GetComponent <ObiCatmullRomCurve>(); //ObiRopeCursor cursor = ropeObject.GetComponent<ObiRopeCursor>(); // set up component references rope.Solver = solver; rope.ropePath = path; rope.section = (ObiRopeSection)Resources.Load("DefaultRopeSection"); rope.GetComponent <MeshRenderer>().material = material; //cursor.rope = rope; // Calculate rope start/end and direction in local space: (plus offset) Vector3 localStart = transform.InverseTransformPoint(chutes[0].transform.position + new Vector3(0, 0.2f, 0)); Vector3 localEnd = transform.InverseTransformPoint(payloads[0].transform.position + new Vector3(0, 0.5f, 0)); Vector3 direction = (localEnd - localStart).normalized; // Generate rope path: path.controlPoints.Clear(); path.controlPoints.Add(localStart - direction); path.controlPoints.Add(localStart); path.controlPoints.Add(localEnd); path.controlPoints.Add(localEnd + direction); //correct thickness, particle resolution, and parenting rope.thickness = 0.025f; rope.resolution = 0.05f; rope.transform.parent = payloads[0].transform; yield return(rope.StartCoroutine(rope.GeneratePhysicRepresentationForMesh())); rope.AddToSolver(null); //extractionCollider = new ObiCollider(); //cargoCollider = new ObiCollider(); BoxCollider extractionBox = chutes[0].AddComponent <BoxCollider>(); extractionBox.size = Vector3.zero; BoxCollider cargoBox = payloads[0].AddComponent <BoxCollider>(); cargoBox.center = new Vector3(0.0f, 0.25f, 0.0f); cargoBox.size = new Vector3(0.5f, 0.5f, 0.5f); extractionCollider = chutes[0].AddComponent <ObiCollider>(); cargoCollider = payloads[0].AddComponent <ObiCollider>(); // remove the constraints from the solver, because we cannot modify the constraints list while the solver is using it. rope.PinConstraints.RemoveFromSolver(null); ObiPinConstraintBatch constraintsBatch = rope.PinConstraints.GetFirstBatch(); constraintsBatch.AddConstraint(0, extractionCollider, Vector3.zero, 0.0f); constraintsBatch.AddConstraint(rope.UsedParticles - 1, cargoCollider, new Vector3(0, 0.5f, -0.25f), 0.0f); rope.PinConstraints.AddToSolver(null); rope.PinConstraints.PushDataToSolver(); }
void Start() { cursor = GetComponentInChildren <ObiRopeCursor>(); rope = cursor.GetComponent <ObiRope>(); cursor.ChangeLength(length); }
private void Start() { // Получить компоненты Rope и Solver _obiR = gameObject.GetComponent <ObiRope>(); _solver = _obiR.solver; }
// Use this for initialization void Start() { cursor = GetComponentInChildren <ObiRopeCursor>(); //gets the cursor component on the rope object rope = cursor.GetComponent <ObiRope>(); }
IEnumerator Setup() { extractionObject = (GameObject)Instantiate(models[0]); heavyCargoObject = (GameObject)Instantiate(models[1]); extractionObject.transform.position = initialExtractionPos; heavyCargoObject.transform.position = initialHeavyCargoPos; start = extractionObject.transform; end = heavyCargoObject.transform; // Get all needed components and interconnect them: rope = GetComponent <ObiRope>(); path = GetComponent <ObiCatmullRomCurve>(); rope.Solver = (ObiSolver)Instantiate(solver); rope.ropePath = path; rope.section = section; GetComponent <MeshRenderer>().material = material; // Calculate rope start/end and direction in local space: (plus offset) Vector3 localStart = transform.InverseTransformPoint(start.position + new Vector3(0, 0.2f, 0)); Vector3 localEnd = transform.InverseTransformPoint(end.position + new Vector3(0, 0.5f, 0)); Vector3 direction = (localEnd - localStart).normalized; // Generate rope path: path.controlPoints.Clear(); path.controlPoints.Add(localStart - direction); path.controlPoints.Add(localStart); path.controlPoints.Add(localEnd); path.controlPoints.Add(localEnd + direction); //correct thickness, particle resolution, and parenting rope.thickness = 0.025f; rope.resolution = 0.05f; rope.transform.parent = heavyCargoObject.transform; // Generate particles and add them to solver: yield return(StartCoroutine(rope.GeneratePhysicRepresentationForMesh())); rope.AddToSolver(null); // Fix first and last particle in place: //rope.invMasses[0] = 0; //rope.invMasses[rope.UsedParticles-1] = 0; //Oni.SetParticleInverseMasses(solver.OniSolver,new float[]{0},1,rope.particleIndices[0]); //Oni.SetParticleInverseMasses(solver.OniSolver,new float[]{0},1,rope.particleIndices[rope.UsedParticles-1]); constraints = rope.GetComponent <ObiPinConstraints>(); constraintsBatch = rope.PinConstraints.GetFirstBatch(); extractionCollider = new ObiCollider(); cargoCollider = new ObiCollider(); BoxCollider extractionBox = extractionObject.AddComponent <BoxCollider>(); extractionBox.size = Vector3.zero; BoxCollider cargoBox = heavyCargoObject.AddComponent <BoxCollider>(); cargoBox.center = new Vector3(0.0f, 0.5f, 0.0f); extractionCollider = extractionObject.AddComponent(typeof(ObiCollider)) as ObiCollider; cargoCollider = heavyCargoObject.AddComponent(typeof(ObiCollider)) as ObiCollider; // remove the constraints from the solver, because we cannot modify the constraints list while the solver is using it. constraints.RemoveFromSolver(null); constraintsBatch.AddConstraint(0, extractionCollider, Vector3.zero, 0.0f); constraintsBatch.AddConstraint(rope.UsedParticles - 1, cargoCollider, Vector3.zero, 0.0f); constraints.AddToSolver(null); constraints.PushDataToSolver(); }
// Use this for initialization void Start() { cursor = GetComponentInChildren <ObiRopeCursor>(); rope = cursor.GetComponent <ObiRope>(); PlayerAndJoystickController.Instance.RopeSize += RopeSizeController; }
// Use this for initialization void Start() { rope = GetComponent <ObiRope>(); cursor = GetComponent <ObiRopeCursor>(); }
void Start() { GameObject solverObject = new GameObject("String Solver", typeof(ObiSolver), typeof(ObiFixedUpdater)); ObiSolver solver = solverObject.GetComponent <ObiSolver>(); ObiFixedUpdater updater = solverObject.GetComponent <ObiFixedUpdater>(); updater.solvers.Add(solver); solverObject.AddComponent(typeof(HexPathFinder)); solver.distanceConstraintParameters = new Oni.ConstraintParameters(true, Oni.ConstraintParameters.EvaluationOrder.Sequential, 100); solver.particleCollisionConstraintParameters = new Oni.ConstraintParameters(true, Oni.ConstraintParameters.EvaluationOrder.Sequential, 30); solver.collisionConstraintParameters = new Oni.ConstraintParameters(true, Oni.ConstraintParameters.EvaluationOrder.Sequential, 30); solver.tetherConstraintParameters = new Oni.ConstraintParameters(true, Oni.ConstraintParameters.EvaluationOrder.Sequential, 50); // Disable solver.skinConstraintParameters = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1); solver.densityConstraintParameters = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1); solver.stretchShearConstraintParameters = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1); solver.stitchConstraintParameters = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1); solver.volumeConstraintParameters = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1); solver.bendTwistConstraintParameters = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1); solver.shapeMatchingConstraintParameters = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1); // solver.frictionConstraintParameters = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1); // solver.particleFrictionConstraintParameters = new Oni.ConstraintParameters(false, Oni.ConstraintParameters.EvaluationOrder.Sequential, 1); // create the blueprint: (ltObiRopeBlueprint, ObiRodBlueprint) var blueprint = ScriptableObject.CreateInstance <ObiRopeBlueprint>(); blueprint.pooledParticles = 20000; blueprint.resolution = 1f; // Procedurally generate the rope path (a simple straight line): blueprint.path.Clear(); blueprint.path.AddControlPoint( new Vector3(0, 0.011f, 0), -Vector3.right, Vector3.right, Vector3.up, 0.005f, 0.005f, 0.03f, 1, Color.white, "start" ); blueprint.path.AddControlPoint( new Vector3(0, 0.5f, 0), -Vector3.right, Vector3.right, Vector3.up, 0.005f, 0.005f, 0.03f, 1, Color.white, "end" ); blueprint.path.FlushEvents(); blueprint.GenerateImmediate(); GameObject ropeObject = new GameObject("String", typeof(ObiRope), typeof(ObiRopeExtrudedRenderer)); ObiRope rope = ropeObject.GetComponent <ObiRope>(); ObiRopeExtrudedRenderer ropeRenderer = ropeObject.GetComponent <ObiRopeExtrudedRenderer>(); MeshRenderer ropeMesh = ropeObject.GetComponent <MeshRenderer>(); if (stringMaterial == null) { ropeMesh.material = new Material(Shader.Find("StringShader")); } else { ropeMesh.material = stringMaterial; } ropeRenderer.section = Resources.Load <ObiRopeSection>("DefaultRopeSection"); rope.ropeBlueprint = ScriptableObject.Instantiate(blueprint); rope.transform.parent = solver.transform; // rope.collisionMaterial = collisionMaterial; rope.selfCollisions = false; rope.stretchingScale = 1; ObiRopeCursor cursor = ropeObject.AddComponent(typeof(ObiRopeCursor)) as ObiRopeCursor; cursor.cursorMu = 0.5f; cursor.sourceMu = 0.5f; ObiParticleAttachment groundAttach = ropeObject.AddComponent(typeof(ObiParticleAttachment)) as ObiParticleAttachment; ObiParticleAttachment charAttach = ropeObject.AddComponent(typeof(ObiParticleAttachment)) as ObiParticleAttachment; groundAttach.target = GameObject.Find("Floor").transform; // groundAttach.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic; groundAttach.particleGroup = blueprint.groups[0]; charAttach.target = GameObject.Find("Ariadne").transform; charAttach.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic; charAttach.particleGroup = blueprint.groups[1]; ropeObject.AddComponent(typeof(StringController)); }
// Use this for initialization void Start() { cursor = GetComponentInChildren <ObiRopeCursor>(); rope = cursor.GetComponent <ObiRope>(); }
private void OnTriggerEnter(Collider other) { if (!other.CompareTag("Cable")) { return; } ObiCollider obicollider = other.GetComponent <ObiCollider>(); obiRope = other.transform.parent.GetComponentInChildren <ObiRope>(); ObiPinConstraints pinConstrain = other.transform.parent.GetComponentInChildren <ObiPinConstraints>(); pinConstraintBatch = pinConstrain.GetFirstBatch(); Debug.Log("Total Particle" + obiRope.TotalParticles); Debug.Log("Used Particle" + obiRope.UsedParticles); Debug.Log("Pooled Particle" + obiRope.PooledParticles); foreach (var item in pinConstraintBatch.pinBodies) { Debug.Log(item.gameObject.name); } foreach (var item in pinConstraintBatch.pinIndices) { Debug.Log(item); } foreach (var item in pinConstraintBatch.GetConstraintsInvolvingParticle(particledex)) { Debug.Log("Constrain of Last pariticle" + item); } pinConstrain.RemoveFromSolver(null); UpdateIndex(); int CheckPoint = 0; Debug.Log("CheckPoin" + CheckPoint++); UpdateIndex(); NameOfParticleLast = pinConstraintBatch.pinBodies[LastParticleConstrainIndex].gameObject.name; NameOfParticleFirst = pinConstraintBatch.pinBodies[FirstParticleConstrainIndex].gameObject.name; if (other.name == NameOfParticleLast) { pinConstraintBatch.RemoveConstraint(LastParticleConstrainIndex); pinConstraintBatch.AddConstraint(obiRope.UsedParticles - 1, GetComponent <ObiColliderBase>(), transform.InverseTransformPoint(obiRope.GetParticlePosition(TestRope.UsedParticles - 1)), Quaternion.identity, 0); UpdateIndex(); Debug.Log("CheckPoin" + CheckPoint++); pinConstraintBatch.RemoveConstraint(SecondLastParticleConstrainIndex); pinConstraintBatch.AddConstraint(obiRope.UsedParticles - 2, GetComponent <ObiColliderBase>(), transform.InverseTransformPoint(obiRope.GetParticlePosition(TestRope.UsedParticles - 2)), Quaternion.identity, 0); Debug.Log("CheckPoin" + CheckPoint++); } else if (other.name == NameOfParticleFirst) { pinConstraintBatch.RemoveConstraint(FirstParticleConstrainIndex); pinConstraintBatch.AddConstraint(0, GetComponent <ObiColliderBase>(), transform.InverseTransformPoint(obiRope.GetParticlePosition(0)), Quaternion.identity, 0); Debug.Log("CheckPoin" + CheckPoint++); UpdateIndex(); pinConstraintBatch.RemoveConstraint(SecondParticleConstrainIndex); pinConstraintBatch.AddConstraint(1, GetComponent <ObiColliderBase>(), transform.InverseTransformPoint(obiRope.GetParticlePosition(1)), Quaternion.identity, 0); } pinConstrain.AddToSolver(null); }