Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moving Rope in runtime
#1
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.

Reply
#2
(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;

   }
}
Reply