private void Test() { client = new OSCClient(IPAddress.Parse("127.0.0.1"), listenPort); OSCMessage m = new OSCMessage("/testMessage"); client.Send(m); client.Flush(); client.Close(); client = null; }
void LateUpdate() { if (flyAround) { Vector3 newPos = center; newPos.x = Mathf.Cos(Time.time); newPos.z = Mathf.Sin(Time.time); transform.position = newPos; } OSCMessage msg = new OSCMessage("/rigidBody"); msg.Append(id); msg.Append(name); Vector3 pos = transform.position; Quaternion rot = transform.rotation; //position msg.Append(pos.x); msg.Append(pos.y); msg.Append(pos.z); //rotation (quat) msg.Append(rot.x); msg.Append(rot.y); msg.Append(rot.z); msg.Append(rot.w); //velocity msg.Append(0f); msg.Append(0f); msg.Append(0f); //angvelocity msg.Append(0f); msg.Append(0f); msg.Append(0f); //isActive msg.Append(1); //always active client.Send(msg); client.Flush(); }
protected override void ApplyTransformUpdate(Vector3 position, Quaternion rotation) { //our gear if (name == handShakedName) { if (verticalWalking) { if (rBody == null) { rBody = t.GetComponent <Rigidbody>(); if (rBody == null) { rBody = t.gameObject.AddComponent <Rigidbody>(); rBody.useGravity = false; } } //snap to near-ground float yOffset = OptiTrackOSCClient.GetPosition().y; physicalY = position.y - yOffset; Vector3 objectPosition = t.position; //move object to correct X/Z position objectPosition.x = position.x; objectPosition.z = position.z; //raycast down from object RaycastHit hitInfo; //TODO: figure out if we need to raycast from closer to the floor (so we don't teleport on top of stuff too much) if (Physics.Raycast(objectPosition, -Vector3.up, out hitInfo, 2f, 1 << 8)) { objectPosition.y += (physicalY - hitInfo.distance); t.position = objectPosition; rBody.velocity = Vector3.zero; } else { t.position = objectPosition; if (canFall) { if (withAccelleration) { rBody.AddForce(-Vector3.up * 9.81f, ForceMode.Acceleration); } else { rBody.velocity = -3 * Vector3.up; } } } //send OSC Message for position OSCMessage m = new OSCMessage("/gear-virtualpos"); m.Append(name); m.Append(objectPosition.x); m.Append(objectPosition.y); m.Append(objectPosition.z); handshakeClient.Send(m); handshakeClient.Flush(); //when previewing in editor, apply rotation (Gear's handle this themselves) #if UNITY_EDITOR t.rotation = rotation; #endif } else { //TODO: test t.position = position; #if UNITY_EDITOR t.rotation = rotation; #endif } } //other player's gear else { if (verticalWalking) { //TODO: test //ignore y, but store it for reference float yOffset = OptiTrackOSCClient.GetPosition().y; physicalY = position.y - yOffset; Vector3 alternateP = t.position; alternateP.x = position.x; alternateP.z = position.z; t.position = alternateP; } else { //TODO: test //business as usual t.position = position; t.rotation = rotation; } } }