- Home /
Question by
THESUBMATRIX · Jun 19, 2016 at 08:27 PM ·
transformunityeditortranslateosc
Why does the cube continue moving upward after I tell it to move down afterward?
public var RemoteIP : String = "127.0.0.1"; //127.0.0.1 signifies a local host (if testing locally
public var SendToPort : int = 9000; //the port you will be sending from
public var ListenerPort : int = 8050; //the port you will be listening on
public var controller : Transform;
//public var gameReceiver = "Cube"; //the tag of the object on stage that you want to manipulate
private var handler : Osc;
public var speed: float;
public var go: GameObject;
public var height: int = 0;
//VARIABLES YOU WANT TO BE ANIMATED
public var yHeight = new Vector3(0,0,0); //the rotation around the y axis
public function Start ()
{
//Initializes on start up to listen for messages
//make sure this game object has both UDPPackIO and OSC script attached
var udp : UDPPacketIO = GetComponent("UDPPacketIO");
udp.init(RemoteIP, SendToPort, ListenerPort);
handler = GetComponent("Osc");
handler.init(udp);
handler.SetAllMessageHandler(AllMessageHandler);
}
Debug.Log("Running");
function Update () {
var step = speed * Time.deltaTime;
go.transform.Translate(yHeight, Space.World);
}
//These functions are called when messages are received
//Access values via: oscMessage.Values[0], oscMessage.Values[1], etc
public function AllMessageHandler(oscMessage: OscMessage){
var msgString = Osc.OscMessageToString(oscMessage); //the message and value combined
var msgAddress = oscMessage.Address; //the message parameters
var msgValue = oscMessage.Values[0]; //the message value
//Debug.Log(msgString); //log the message and values coming from OSC
//FUNCTIONS YOU WANT CALLED WHEN A SPECIFIC MESSAGE IS RECEIVED
switch (msgAddress){
case "/attention":
Rotate(msgValue);
break;
default:
break;
}
}
//FUNCTIONS CALLED BY MATCHING A SPECIFIC MESSAGE IN THE ALLMESSAGEHANDLER FUNCTION
public function Rotate(msgValue) : void //rotate the cube around its axis
{
height = msgValue/10;
yHeight = new Vector3(0,height,0);
}
Comment