Obi Official Forum
Moving Rope in runtime - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Moving Rope in runtime (/thread-146.html)



Moving Rope in runtime - Parker - 21-09-2017

Unity is running.  This will happen in real time, meaning the user will not stop the program and go to the particle editor, make changes, then run the game again.

I want to move a rope from left side of screen to right side without it fly over all over the place.  I am looking for code to fix this problem.




RE: Moving Rope - josemendez - 21-09-2017

(21-09-2017, 03:32 AM)Parker Wrote: Unity is running.  This will happen in real time, meaning the user will not stop the program and go to the particle editor, make changes, then run the game again.

I want to move a rope from left side of screen to right side without it fly over all over the place.  I am looking for code to fix this problem.


Just disable the rope,  move it to a new location, wait for the next physics update and reenable it. Something like this:

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

public class ObiActorTeleport : MonoBehaviour {

   public ObiActor actor;

       void Update () {
       if (Input.anyKeyDown)
           StartCoroutine(Teleport());
       }

   IEnumerator Teleport(){

       actor.enabled = false;

       // change position here. I'm just teleporting the rope somewhere inside a sphere of radius 2:
       actor.transform.position = UnityEngine.Random.insideUnitSphere * 2;

       yield return new WaitForFixedUpdate();
       actor.enabled = true;

   }
}