• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by potter3366 · Dec 26, 2012 at 02:30 AM · rotationosc

Problem with rotation via OSC

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

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
  
 public class UnityOSCListener : MonoBehaviour  {
    
     public static float angle;
    
     public void OSCMessageReceived(OSC.NET.OSCMessage message){ 
         string address = message.Address;
         ArrayList args = message.Values;
        
         if (address == "/angles") {
             angle = (float)args[0];
         }
     }   
 }

RotateAroundPivot.cs

 using System;
 using System.Collections;
 using System.Reflection;
 using UnityEngine;
      
 public class RotateAroundPivot : MonoBehaviour
 {
    
     private bool moving = false;
     private float angle1;
        
     void FixedUpdate()
     {
         if(!moving) {
             moving = true;
             angle1 = UnityOSCListener.angle;
             iTween.RotateBy(gameObject, iTween.Hash("y", angle1, "oncomplete", "resetMoving", "easeType", "easeInOutBack", "delay", .6));
         }
     }
    
     void resetMoving() {
         moving = false;
     }
        
 }
 
 ///////////////////////////////////////////////////////////


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by potter3366 · Dec 26, 2012 at 12:59 PM

SOLVED !!!

 public class UnityOSCListener : MonoBehaviour  {
     
     public RotateAroundPivot script;
     private float angle;
     
     void Start(){
         script = GetComponentInChildren<RotateAroundPivot>();
     }
     
     public void OSCMessageReceived(OSC.NET.OSCMessage message){    
         string address = message.Address;
         ArrayList args = message.Values;
         
         if (address == "/angles") {
             angle = (float)args[0];
         }
         
         script.DoRotate(angle);
     }
     
 }


 public class RotateAroundPivot : MonoBehaviour
 {       
     public void DoRotate(float angle1)
     {
         iTween.RotateBy(gameObject, iTween.Hash("y", angle1, "easeType", "easeInOutBack", "delay", .6));
     }
 }



Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Next Beat Games · Dec 26, 2012 at 03:20 AM

You are using resetMoving as the oncomplete function in your itween. ResetMoving will set moving to false and the condition in fixedUpdate will evaluate to true since moving is false.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Next Beat Games · Dec 26, 2012 at 03:21 AM 0
Share

I can post an alternative for you in a few $$anonymous$$utes

avatar image Next Beat Games · Dec 26, 2012 at 03:23 AM 0
Share

have UnityOSCListener call RotateAroundPivot's DoRotate() - rename fixedupdate to DoRotate(). You can also delete the variable 'moving' since its private. if you make it public other objects can check if RotateAroundPivot is busy doing its iTween. If you dont need that information, you might as well delete 'moving'

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Flip over an object (smooth transition) 3 Answers

Angle to Rotation 2 Answers

Changing the forward rotation for LookAt 2 Answers

how to rotate gameobject only in multiple of 36 degree ? 1 Answer

turret rotation accuracy problem 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges