Search Unity

Problem with rotation via OSC

Discussion in 'Scripting' started by potter3366, Dec 26, 2012.

  1. potter3366

    potter3366

    Joined:
    Oct 15, 2009
    Posts:
    65
    The rotation angle values are coming one by one after mouse clicking over OSC message from processing app.
    What I want:
    If I fill in the text box in processing app angle value and click SEND then the value entered will be sent to Unity.
    The object has to rotate only this for example 0.35 rad. But it continues its rotation on and on..

    UnityOSCListener.cs

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class UnityOSCListener : MonoBehaviour  {
    6.    
    7.     public static float angle;
    8.    
    9.     public void OSCMessageReceived(OSC.NET.OSCMessage message){
    10.         string address = message.Address;
    11.         ArrayList args = message.Values;
    12.        
    13.         if (address == "/angles") {
    14.             angle = (float)args[0];
    15.         }
    16.     }  
    17. }
    RotateAroundPivot.cs

    Code (csharp):
    1. using System;
    2. using System.Collections;
    3. using System.Reflection;
    4. using UnityEngine;
    5.      
    6. public class RotateAroundPivot : MonoBehaviour
    7. {
    8.    
    9.     private bool moving = false;
    10.     private float angle1;
    11.        
    12.     void FixedUpdate()
    13.     {
    14.         if(!moving) {
    15.             moving = true;
    16.             angle1 = UnityOSCListener.angle;
    17.             iTween.RotateBy(gameObject, iTween.Hash("y", angle1, "oncomplete", "resetMoving", "easeType", "easeInOutBack", "delay", .6));
    18.         }
    19.     }
    20.    
    21.     void resetMoving() {
    22.         moving = false;
    23.     }
    24.        
    25. }